]> git.lizzy.rs Git - rust.git/commitdiff
Delete send_str, rewrite clients on top of MaybeOwned<'static>
authorKevin Ballard <kevin@sb.org>
Sat, 8 Feb 2014 00:36:59 +0000 (16:36 -0800)
committerKevin Ballard <kevin@sb.org>
Sat, 8 Feb 2014 06:31:52 +0000 (22:31 -0800)
Declare a `type SendStr = MaybeOwned<'static>` to ease readibility of
types that needed the old SendStr behavior.

Implement all the traits for MaybeOwned that SendStr used to implement.

14 files changed:
src/etc/vim/syntax/rust.vim
src/libextra/test.rs
src/libgreen/lib.rs
src/libgreen/task.rs
src/libnative/task.rs
src/libstd/lib.rs
src/libstd/prelude.rs
src/libstd/rt/task.rs
src/libstd/send_str.rs [deleted file]
src/libstd/str.rs
src/libstd/task.rs
src/test/run-fail/fail-task-name-send-str.rs
src/test/run-pass/send_str_hashmap.rs
src/test/run-pass/send_str_treemap.rs

index 0d248354b737b47ac2416bbb2bc7ddbdfdb235db..9aa76cad83e27dbf0ab6315e1b92cff1696b72bd 100644 (file)
@@ -87,8 +87,7 @@ syn keyword rustTrait Primitive Int Float ToStrRadix ToPrimitive FromPrimitive
 syn keyword rustTrait GenericPath Path PosixPath WindowsPath
 syn keyword rustTrait RawPtr
 syn keyword rustTrait Buffer Writer Reader Seek
-syn keyword rustTrait SendStr SendStrOwned SendStrStatic IntoSendStr
-syn keyword rustTrait Str StrVector StrSlice OwnedStr
+syn keyword rustTrait Str StrVector StrSlice OwnedStr IntoMaybeOwned
 syn keyword rustTrait IterBytes
 syn keyword rustTrait ToStr IntoStr
 syn keyword rustTrait CloneableTuple ImmutableTuple
index d1fffd9e515c18e164962e447198e622f2d5d7d1..2d52a59c8365a5dcff7b50cd7e020392c025b6c0 100644 (file)
@@ -893,8 +893,8 @@ fn run_test_inner(desc: TestDesc,
         spawn(proc() {
             let mut task = task::task();
             task.name(match desc.name {
-                DynTestName(ref name) => SendStrOwned(name.clone()),
-                StaticTestName(name) => SendStrStatic(name),
+                DynTestName(ref name) => name.to_owned().into_maybe_owned(),
+                StaticTestName(name) => name.into_maybe_owned()
             });
             let result_future = task.future_result();
             task.spawn(testfn);
index 30b786e4f19ee5978babc349d595f6bd8158cc4e..c5b221d22724bbc555eabd675033fefaf2b8f242 100644 (file)
@@ -257,7 +257,7 @@ pub fn run(main: proc()) -> int {
     let (port, chan) = Chan::new();
     let mut opts = TaskOpts::new();
     opts.notify_chan = Some(chan);
-    opts.name = Some(SendStrStatic("<main>"));
+    opts.name = Some("<main>".into_maybe_owned());
     pool.spawn(opts, main);
 
     // Wait for the main task to return, and set the process error code
index 4fb61f156809fb200051e6fa0d4477d55a90005f..e492acb4468fd143356839536103da474e33f576 100644 (file)
@@ -510,7 +510,7 @@ fn smoke_fail() {
     #[test]
     fn smoke_opts() {
         let mut opts = TaskOpts::new();
-        opts.name = Some(SendStrStatic("test"));
+        opts.name = Some("test".into_maybe_owned());
         opts.stack_size = Some(20 * 4096);
         let (p, c) = Chan::new();
         opts.notify_chan = Some(c);
index c08e326d903312d80c3561be816e328bc128cfbc..d0ca8364aa7d9a021741d7b2e199135de0418c8b 100644 (file)
@@ -294,7 +294,7 @@ fn smoke_fail() {
     #[test]
     fn smoke_opts() {
         let mut opts = TaskOpts::new();
-        opts.name = Some(SendStrStatic("test"));
+        opts.name = Some("test".into_maybe_owned());
         opts.stack_size = Some(20 * 4096);
         let (p, c) = Chan::new();
         opts.notify_chan = Some(c);
index 0398af9c1c1b4c8566f9ee451621cbb058d80125..7b574d68e78004cc0fb9bd94272ccbd9d3d94bad 100644 (file)
 pub mod str;
 
 pub mod ascii;
-pub mod send_str;
 
 pub mod ptr;
 pub mod owned;
index b08d792822bfb4839dbddd412f8c1a6b822a80d4..f113b2f17ebe6a74c2f70d412220ce2376e206bf 100644 (file)
@@ -63,8 +63,7 @@
 pub use path::{GenericPath, Path, PosixPath, WindowsPath};
 pub use ptr::RawPtr;
 pub use io::{Buffer, Writer, Reader, Seek};
-pub use send_str::{SendStr, SendStrOwned, SendStrStatic, IntoSendStr};
-pub use str::{Str, StrVector, StrSlice, OwnedStr};
+pub use str::{Str, StrVector, StrSlice, OwnedStr, IntoMaybeOwned};
 pub use to_bytes::IterBytes;
 pub use to_str::{ToStr, IntoStr};
 pub use tuple::{CloneableTuple, ImmutableTuple};
index fbe82531f69778f48add0ca2860eba8e660dda5d..a7648dd2d19dffbc47da317da8d83fdeca3bd9d4 100644 (file)
@@ -30,7 +30,7 @@
 use rt::local_heap::LocalHeap;
 use rt::rtio::LocalIo;
 use rt::unwind::Unwinder;
-use send_str::SendStr;
+use str::SendStr;
 use sync::arc::UnsafeArc;
 use sync::atomics::{AtomicUint, SeqCst};
 use task::{TaskResult, TaskOpts};
diff --git a/src/libstd/send_str.rs b/src/libstd/send_str.rs
deleted file mode 100644 (file)
index b075b75..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! The `SendStr` trait for optionally static strings
-
-use clone::{Clone, DeepClone};
-use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv};
-use cmp::Ordering;
-use container::Container;
-use default::Default;
-use str::{Str, StrSlice};
-use to_str::ToStr;
-use to_bytes::{IterBytes, Cb};
-
-/// A SendStr is a string that can hold either a ~str or a &'static str.
-/// This can be useful as an optimization when an allocation is sometimes
-/// needed but the common case is statically known.
-#[allow(missing_doc)]
-pub enum SendStr {
-    SendStrOwned(~str),
-    SendStrStatic(&'static str)
-}
-
-impl SendStr {
-    /// Returns `true` if this `SendStr` wraps an owned string
-    #[inline]
-    pub fn is_owned(&self) -> bool {
-        match *self {
-            SendStrOwned(_) => true,
-            SendStrStatic(_) => false
-        }
-    }
-
-    /// Returns `true` if this `SendStr` wraps a static string
-    #[inline]
-    pub fn is_static(&self) -> bool {
-        match *self {
-            SendStrOwned(_) => false,
-            SendStrStatic(_) => true
-        }
-    }
-}
-
-/// Trait for moving into an `SendStr`
-pub trait IntoSendStr {
-    /// Moves self into an `SendStr`
-    fn into_send_str(self) -> SendStr;
-}
-
-impl IntoSendStr for ~str {
-    #[inline]
-    fn into_send_str(self) -> SendStr { SendStrOwned(self) }
-}
-
-impl IntoSendStr for &'static str {
-    #[inline]
-    fn into_send_str(self) -> SendStr { SendStrStatic(self) }
-}
-
-impl IntoSendStr for SendStr {
-    #[inline]
-    fn into_send_str(self) -> SendStr { self }
-}
-
-/*
-Section: String trait impls.
-`SendStr` should behave like a normal string, so we don't derive.
-*/
-
-impl ToStr for SendStr {
-    #[inline]
-    fn to_str(&self) -> ~str { self.as_slice().to_owned() }
-}
-
-impl Eq for SendStr {
-    #[inline]
-    fn eq(&self, other: &SendStr) -> bool {
-        self.as_slice().equals(&other.as_slice())
-    }
-}
-
-impl TotalEq for SendStr {
-    #[inline]
-    fn equals(&self, other: &SendStr) -> bool {
-        self.as_slice().equals(&other.as_slice())
-    }
-}
-
-impl Ord for SendStr {
-    #[inline]
-    fn lt(&self, other: &SendStr) -> bool {
-        self.as_slice().lt(&other.as_slice())
-    }
-}
-
-impl TotalOrd for SendStr {
-    #[inline]
-    fn cmp(&self, other: &SendStr) -> Ordering {
-        self.as_slice().cmp(&other.as_slice())
-    }
-}
-
-impl<'a, S: Str> Equiv<S> for SendStr {
-    #[inline]
-    fn equiv(&self, other: &S) -> bool {
-        self.as_slice().equals(&other.as_slice())
-    }
-}
-
-impl Str for SendStr {
-    #[inline]
-    fn as_slice<'r>(&'r self) -> &'r str {
-        match *self {
-            SendStrOwned(ref s) => s.as_slice(),
-            // FIXME: Borrowchecker doesn't recognize lifetime as static unless prompted
-            // SendStrStatic(s) => s.as_slice()
-            SendStrStatic(s)    => {let tmp: &'static str = s; tmp}
-        }
-    }
-
-    #[inline]
-    fn into_owned(self) -> ~str {
-        match self {
-            SendStrOwned(s)  => s,
-            SendStrStatic(s) => s.to_owned()
-        }
-    }
-}
-
-impl Container for SendStr {
-    #[inline]
-    fn len(&self) -> uint { self.as_slice().len() }
-}
-
-impl Clone for SendStr {
-    #[inline]
-    fn clone(&self) -> SendStr {
-        match *self {
-            SendStrOwned(ref s) => SendStrOwned(s.to_owned()),
-            SendStrStatic(s)    => SendStrStatic(s)
-        }
-    }
-}
-
-impl DeepClone for SendStr {
-    #[inline]
-    fn deep_clone(&self) -> SendStr {
-        match *self {
-            SendStrOwned(ref s) => SendStrOwned(s.to_owned()),
-            SendStrStatic(s)    => SendStrStatic(s)
-        }
-    }
-}
-
-impl Default for SendStr {
-    #[inline]
-    fn default() -> SendStr { SendStrStatic("") }
-}
-
-impl IterBytes for SendStr {
-    #[inline]
-    fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
-        match *self {
-            SendStrOwned(ref s) => s.iter_bytes(lsb0, f),
-            SendStrStatic(s)    => s.iter_bytes(lsb0, f)
-        }
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use prelude::*;
-    use send_str::{SendStrOwned, SendStrStatic};
-
-    #[test]
-    fn test_send_str_traits() {
-        let s = SendStrStatic("abcde");
-        assert_eq!(s.len(), 5);
-        assert_eq!(s.as_slice(), "abcde");
-        assert_eq!(s.to_str(), ~"abcde");
-        assert!(s.lt(&SendStrOwned(~"bcdef")));
-        assert_eq!(SendStrStatic(""), Default::default());
-
-        let o = SendStrOwned(~"abcde");
-        assert_eq!(o.len(), 5);
-        assert_eq!(o.as_slice(), "abcde");
-        assert_eq!(o.to_str(), ~"abcde");
-        assert!(o.lt(&SendStrStatic("bcdef")));
-        assert_eq!(SendStrOwned(~""), Default::default());
-
-        assert_eq!(s.cmp(&o), Equal);
-        assert!(s.equals(&o));
-        assert!(s.equiv(&o));
-
-        assert_eq!(o.cmp(&s), Equal);
-        assert!(o.equals(&s));
-        assert!(o.equiv(&s));
-    }
-
-    #[test]
-    fn test_send_str_methods() {
-        let s = SendStrStatic("abcde");
-        assert!(s.is_static());
-        assert!(!s.is_owned());
-
-        let o = SendStrOwned(~"abcde");
-        assert!(!o.is_static());
-        assert!(o.is_owned());
-    }
-
-    #[test]
-    fn test_send_str_clone() {
-        assert_eq!(SendStrOwned(~"abcde"), SendStrStatic("abcde").clone());
-        assert_eq!(SendStrOwned(~"abcde"), SendStrStatic("abcde").deep_clone());
-
-        assert_eq!(SendStrOwned(~"abcde"), SendStrOwned(~"abcde").clone());
-        assert_eq!(SendStrOwned(~"abcde"), SendStrOwned(~"abcde").deep_clone());
-
-        assert_eq!(SendStrStatic("abcde"), SendStrStatic("abcde").clone());
-        assert_eq!(SendStrStatic("abcde"), SendStrStatic("abcde").deep_clone());
-
-        assert_eq!(SendStrStatic("abcde"), SendStrOwned(~"abcde").clone());
-        assert_eq!(SendStrStatic("abcde"), SendStrOwned(~"abcde").deep_clone());
-    }
-
-    #[test]
-    fn test_send_str_into_owned() {
-        assert_eq!(SendStrStatic("abcde").into_owned(), ~"abcde");
-        assert_eq!(SendStrOwned(~"abcde").into_owned(), ~"abcde");
-    }
-
-    #[test]
-    fn test_into_send_str() {
-        assert_eq!("abcde".into_send_str(), SendStrStatic("abcde"));
-        assert_eq!((~"abcde").into_send_str(), SendStrStatic("abcde"));
-        assert_eq!("abcde".into_send_str(), SendStrOwned(~"abcde"));
-        assert_eq!((~"abcde").into_send_str(), SendStrOwned(~"abcde"));
-    }
-}
index 204139c5d78d61803082780e5bcfc68f912af3fb..3225bb3a6789c30f180627ea675c748ccadde76b 100644 (file)
@@ -86,7 +86,9 @@ fn main() {
 use char;
 use char::Char;
 use clone::{Clone, DeepClone};
+use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering};
 use container::{Container, Mutable};
+use fmt;
 use iter::{Iterator, FromIterator, Extendable, range};
 use iter::{Filter, AdditiveIterator, Map};
 use iter::{Rev, DoubleEndedIterator, ExactSize};
@@ -100,7 +102,7 @@ fn main() {
 use vec;
 use vec::{OwnedVector, OwnedCloneableVector, ImmutableVector, MutableVector};
 use default::Default;
-use send_str::{SendStr, SendStrOwned};
+use to_bytes::{IterBytes, Cb};
 use unstable::raw::Repr;
 
 /*
@@ -915,53 +917,6 @@ macro_rules! utf8_acc_cont_byte(
 
 static TAG_CONT_U8: u8 = 128u8;
 
-/// Enum that represents either a borrowed or an owned string.
-#[deriving(Eq,Clone)]
-pub enum MaybeOwned<'a> {
-    /// A borrowed string
-    Slice(&'a str),
-    /// An owned string
-    Owned(~str)
-}
-
-impl<'a> Str for MaybeOwned<'a> {
-    #[inline]
-    fn as_slice<'b>(&'b self) -> &'b str {
-        match *self {
-            Slice(s) => s,
-            Owned(ref s) => s.as_slice()
-        }
-    }
-
-    #[inline]
-    fn into_owned(self) -> ~str {
-        match self {
-            Slice(s) => s.to_owned(),
-            Owned(s) => s
-        }
-    }
-}
-
-impl<'a> ToStr for MaybeOwned<'a> {
-    #[inline]
-    fn to_str(&self) -> ~str {
-        match *self {
-            Slice(s) => s.to_str(),
-            Owned(ref s) => s.clone()
-        }
-    }
-}
-
-impl<'a> ::fmt::Show for MaybeOwned<'a> {
-    #[inline]
-    fn fmt(mo: &MaybeOwned, f: &mut ::fmt::Formatter) -> ::fmt::Result {
-        match *mo {
-            Slice(ref s) => ::fmt::Show::fmt(s, f),
-            Owned(ref s) => ::fmt::Show::fmt(&s.as_slice(), f)
-        }
-    }
-}
-
 /// Converts a vector of bytes to a new utf-8 string.
 /// Any invalid utf-8 sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
 ///
@@ -1083,6 +1038,172 @@ macro_rules! error(() => ({
     Owned(res)
 }
 
+/*
+Section: MaybeOwned
+*/
+
+/// A MaybeOwned is a string that can hold either a ~str or a &str.
+/// This can be useful as an optimization when an allocation is sometimes
+/// needed but not always.
+pub enum MaybeOwned<'a> {
+    /// A borrowed string
+    Slice(&'a str),
+    /// An owned string
+    Owned(~str)
+}
+
+/// SendStr is a specialization of `MaybeOwned` to be sendable
+pub type SendStr = MaybeOwned<'static>;
+
+impl<'a> MaybeOwned<'a> {
+    /// Returns `true` if this `MaybeOwned` wraps an owned string
+    #[inline]
+    pub fn is_owned(&self) -> bool {
+        match *self {
+            Slice(_) => false,
+            Owned(_) => true
+        }
+    }
+
+    /// Returns `true` if this `MaybeOwned` wraps a borrowed string
+    #[inline]
+    pub fn is_slice(&self) -> bool {
+        match *self {
+            Slice(_) => true,
+            Owned(_) => false
+        }
+    }
+}
+
+/// Trait for moving into a `MaybeOwned`
+pub trait IntoMaybeOwned<'a> {
+    /// Moves self into a `MaybeOwned`
+    fn into_maybe_owned(self) -> MaybeOwned<'a>;
+}
+
+impl<'a> IntoMaybeOwned<'a> for ~str {
+    #[inline]
+    fn into_maybe_owned(self) -> MaybeOwned<'a> { Owned(self) }
+}
+
+impl<'a> IntoMaybeOwned<'a> for &'a str {
+    #[inline]
+    fn into_maybe_owned(self) -> MaybeOwned<'a> { Slice(self) }
+}
+
+impl<'a> IntoMaybeOwned<'a> for MaybeOwned<'a> {
+    #[inline]
+    fn into_maybe_owned(self) -> MaybeOwned<'a> { self }
+}
+
+impl<'a> ToStr for MaybeOwned<'a> {
+    #[inline]
+    fn to_str(&self) -> ~str { self.as_slice().to_owned() }
+}
+
+impl<'a> Eq for MaybeOwned<'a> {
+    #[inline]
+    fn eq(&self, other: &MaybeOwned) -> bool {
+        self.as_slice().equals(&other.as_slice())
+    }
+}
+
+impl<'a> TotalEq for MaybeOwned<'a> {
+    #[inline]
+    fn equals(&self, other: &MaybeOwned) -> bool {
+        self.as_slice().equals(&other.as_slice())
+    }
+}
+
+impl<'a> Ord for MaybeOwned<'a> {
+    #[inline]
+    fn lt(&self, other: &MaybeOwned) -> bool {
+        self.as_slice().lt(&other.as_slice())
+    }
+}
+
+impl<'a> TotalOrd for MaybeOwned<'a> {
+    #[inline]
+    fn cmp(&self, other: &MaybeOwned) -> Ordering {
+        self.as_slice().cmp(&other.as_slice())
+    }
+}
+
+impl<'a, S: Str> Equiv<S> for MaybeOwned<'a> {
+    #[inline]
+    fn equiv(&self, other: &S) -> bool {
+        self.as_slice().equals(&other.as_slice())
+    }
+}
+
+impl<'a> Str for MaybeOwned<'a> {
+    #[inline]
+    fn as_slice<'b>(&'b self) -> &'b str {
+        match *self {
+            Slice(s) => s,
+            Owned(ref s) => s.as_slice()
+        }
+    }
+
+    #[inline]
+    fn into_owned(self) -> ~str {
+        match self {
+            Slice(s) => s.to_owned(),
+            Owned(s) => s
+        }
+    }
+}
+
+impl<'a> Container for MaybeOwned<'a> {
+    #[inline]
+    fn len(&self) -> uint { self.as_slice().len() }
+}
+
+impl<'a> Clone for MaybeOwned<'a> {
+    #[inline]
+    fn clone(&self) -> MaybeOwned<'a> {
+        match *self {
+            Slice(s) => Slice(s),
+            Owned(ref s) => Owned(s.to_owned())
+        }
+    }
+}
+
+impl<'a> DeepClone for MaybeOwned<'a> {
+    #[inline]
+    fn deep_clone(&self) -> MaybeOwned<'a> {
+        match *self {
+            Slice(s) => Slice(s),
+            Owned(ref s) => Owned(s.to_owned())
+        }
+    }
+}
+
+impl<'a> Default for MaybeOwned<'a> {
+    #[inline]
+    fn default() -> MaybeOwned<'a> { Slice("") }
+}
+
+impl<'a> IterBytes for MaybeOwned<'a> {
+    #[inline]
+    fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
+        match *self {
+            Slice(s) => s.iter_bytes(lsb0, f),
+            Owned(ref s) => s.iter_bytes(lsb0, f)
+        }
+    }
+}
+
+impl<'a> fmt::Show for MaybeOwned<'a> {
+    #[inline]
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
+            Slice(ref s) => s.fmt(f),
+            Owned(ref s) => s.fmt(f)
+        }
+    }
+}
+
 /// Unsafe operations
 pub mod raw {
     use cast;
@@ -1837,9 +1958,6 @@ pub trait StrSlice<'a> {
     /// Converts to a vector of `u16` encoded as UTF-16.
     fn to_utf16(&self) -> ~[u16];
 
-    /// Copy a slice into a new `SendStr`.
-    fn to_send_str(&self) -> SendStr;
-
     /// Check that `index`-th byte lies at the start and/or end of a
     /// UTF-8 code point sequence.
     ///
@@ -2364,11 +2482,6 @@ fn to_utf16(&self) -> ~[u16] {
         u
     }
 
-    #[inline]
-    fn to_send_str(&self) -> SendStr {
-        SendStrOwned(self.to_owned())
-    }
-
     #[inline]
     fn is_char_boundary(&self, index: uint) -> bool {
         if index == self.len() { return true; }
@@ -2808,7 +2921,6 @@ mod tests {
     use prelude::*;
     use ptr;
     use str::*;
-    use send_str::{SendStrOwned, SendStrStatic};
 
     #[test]
     fn test_eq() {
@@ -4038,17 +4150,76 @@ fn test_str_from_utf8_lossy() {
         assert_eq!(from_utf8_lossy(xs), Owned(~"\uFFFD\uFFFD\uFFFDfoo\uFFFD\uFFFD\uFFFDbar"));
     }
 
-    #[test]
-    fn test_to_send_str() {
-        assert_eq!("abcde".to_send_str(), SendStrStatic("abcde"));
-        assert_eq!("abcde".to_send_str(), SendStrOwned(~"abcde"));
-    }
-
     #[test]
     fn test_from_str() {
       let owned: Option<~str> = from_str(&"string");
       assert_eq!(owned, Some(~"string"));
     }
+
+    #[test]
+    fn test_maybe_owned_traits() {
+        let s = Slice("abcde");
+        assert_eq!(s.len(), 5);
+        assert_eq!(s.as_slice(), "abcde");
+        assert_eq!(s.to_str(), ~"abcde");
+        assert!(s.lt(&Owned(~"bcdef")));
+        assert_eq!(Slice(""), Default::default());
+
+        let o = Owned(~"abcde");
+        assert_eq!(o.len(), 5);
+        assert_eq!(o.as_slice(), "abcde");
+        assert_eq!(o.to_str(), ~"abcde");
+        assert!(o.lt(&Slice("bcdef")));
+        assert_eq!(Owned(~""), Default::default());
+
+        assert_eq!(s.cmp(&o), Equal);
+        assert!(s.equals(&o));
+        assert!(s.equiv(&o));
+
+        assert_eq!(o.cmp(&s), Equal);
+        assert!(o.equals(&s));
+        assert!(o.equiv(&s));
+    }
+
+    #[test]
+    fn test_maybe_owned_methods() {
+        let s = Slice("abcde");
+        assert!(s.is_slice());
+        assert!(!s.is_owned());
+
+        let o = Owned(~"abcde");
+        assert!(!o.is_slice());
+        assert!(o.is_owned());
+    }
+
+    #[test]
+    fn test_maybe_owned_clone() {
+        assert_eq!(Owned(~"abcde"), Slice("abcde").clone());
+        assert_eq!(Owned(~"abcde"), Slice("abcde").deep_clone());
+
+        assert_eq!(Owned(~"abcde"), Owned(~"abcde").clone());
+        assert_eq!(Owned(~"abcde"), Owned(~"abcde").deep_clone());
+
+        assert_eq!(Slice("abcde"), Slice("abcde").clone());
+        assert_eq!(Slice("abcde"), Slice("abcde").deep_clone());
+
+        assert_eq!(Slice("abcde"), Owned(~"abcde").clone());
+        assert_eq!(Slice("abcde"), Owned(~"abcde").deep_clone());
+    }
+
+    #[test]
+    fn test_maybe_owned_into_owned() {
+        assert_eq!(Slice("abcde").into_owned(), ~"abcde");
+        assert_eq!(Owned(~"abcde").into_owned(), ~"abcde");
+    }
+
+    #[test]
+    fn test_into_maybe_owned() {
+        assert_eq!("abcde".into_maybe_owned(), Slice("abcde"));
+        assert_eq!((~"abcde").into_maybe_owned(), Slice("abcde"));
+        assert_eq!("abcde".into_maybe_owned(), Owned(~"abcde"));
+        assert_eq!((~"abcde").into_maybe_owned(), Owned(~"abcde"));
+    }
 }
 
 #[cfg(test)]
index 078933be78fdd01fdd806c3ea30b52f3e90e02af..921d0feaa8b195e65bf58dffd95f2f18b9b1e2af 100644 (file)
@@ -62,8 +62,7 @@
 use result::{Result, Ok, Err};
 use rt::local::Local;
 use rt::task::Task;
-use send_str::{SendStr, IntoSendStr};
-use str::Str;
+use str::{Str, SendStr, IntoMaybeOwned};
 
 #[cfg(test)] use any::{AnyOwnExt, AnyRefExt};
 #[cfg(test)] use comm::SharedChan;
@@ -190,8 +189,8 @@ pub fn future_result(&mut self) -> Port<TaskResult> {
 
     /// Name the task-to-be. Currently the name is used for identification
     /// only in failure messages.
-    pub fn name<S: IntoSendStr>(&mut self, name: S) {
-        self.opts.name = Some(name.into_send_str());
+    pub fn name<S: IntoMaybeOwned<'static>>(&mut self, name: S) {
+        self.opts.name = Some(name.into_maybe_owned());
     }
 
     /**
@@ -396,7 +395,7 @@ fn test_static_named_task() {
 #[test]
 fn test_send_named_task() {
     let mut t = task();
-    t.name("ada lovelace".into_send_str());
+    t.name("ada lovelace".into_maybe_owned());
     t.spawn(proc() {
         with_task_name(|name| {
             assert!(name.unwrap() == "ada lovelace");
index ca2472cfa55f159f2ac5b507f13befebbee3b92a..ea530fe9f69d2019af64317fcf052e3a8087e42d 100644 (file)
@@ -12,7 +12,7 @@
 
 fn main() {
     let mut t = ::std::task::task();
-    t.name("send name".to_send_str());
+    t.name("send name".into_maybe_owned());
     t.try(proc() {
         fail!("test");
         3
index dc7e51c3c2364cb5c60c79933c4b93e71451df7e..8599f9d383605504f99d8a482b64823435662971 100644 (file)
 use std::cmp::Equal;
 use std::container::{Container, Map, MutableMap};
 use std::default::Default;
-use std::send_str::{SendStr, SendStrOwned, SendStrStatic};
-use std::str::Str;
+use std::str::{Str, SendStr, Owned, Slice};
 use std::to_str::ToStr;
 use std::hashmap::HashMap;
 use std::option::Some;
 
 pub fn main() {
     let mut map: HashMap<SendStr, uint> = HashMap::new();
-    assert!(map.insert(SendStrStatic("foo"), 42));
-    assert!(!map.insert(SendStrOwned(~"foo"), 42));
-    assert!(!map.insert(SendStrStatic("foo"), 42));
-    assert!(!map.insert(SendStrOwned(~"foo"), 42));
+    assert!(map.insert(Slice("foo"), 42));
+    assert!(!map.insert(Owned(~"foo"), 42));
+    assert!(!map.insert(Slice("foo"), 42));
+    assert!(!map.insert(Owned(~"foo"), 42));
 
-    assert!(!map.insert(SendStrStatic("foo"), 43));
-    assert!(!map.insert(SendStrOwned(~"foo"), 44));
-    assert!(!map.insert(SendStrStatic("foo"), 45));
-    assert!(!map.insert(SendStrOwned(~"foo"), 46));
+    assert!(!map.insert(Slice("foo"), 43));
+    assert!(!map.insert(Owned(~"foo"), 44));
+    assert!(!map.insert(Slice("foo"), 45));
+    assert!(!map.insert(Owned(~"foo"), 46));
 
     let v = 46;
 
-    assert_eq!(map.find(&SendStrOwned(~"foo")), Some(&v));
-    assert_eq!(map.find(&SendStrStatic("foo")), Some(&v));
+    assert_eq!(map.find(&Owned(~"foo")), Some(&v));
+    assert_eq!(map.find(&Slice("foo")), Some(&v));
 
     let (a, b, c, d) = (50, 51, 52, 53);
 
-    assert!(map.insert(SendStrStatic("abc"), a));
-    assert!(map.insert(SendStrOwned(~"bcd"), b));
-    assert!(map.insert(SendStrStatic("cde"), c));
-    assert!(map.insert(SendStrOwned(~"def"), d));
+    assert!(map.insert(Slice("abc"), a));
+    assert!(map.insert(Owned(~"bcd"), b));
+    assert!(map.insert(Slice("cde"), c));
+    assert!(map.insert(Owned(~"def"), d));
 
-    assert!(!map.insert(SendStrStatic("abc"), a));
-    assert!(!map.insert(SendStrOwned(~"bcd"), b));
-    assert!(!map.insert(SendStrStatic("cde"), c));
-    assert!(!map.insert(SendStrOwned(~"def"), d));
+    assert!(!map.insert(Slice("abc"), a));
+    assert!(!map.insert(Owned(~"bcd"), b));
+    assert!(!map.insert(Slice("cde"), c));
+    assert!(!map.insert(Owned(~"def"), d));
 
-    assert!(!map.insert(SendStrOwned(~"abc"), a));
-    assert!(!map.insert(SendStrStatic("bcd"), b));
-    assert!(!map.insert(SendStrOwned(~"cde"), c));
-    assert!(!map.insert(SendStrStatic("def"), d));
+    assert!(!map.insert(Owned(~"abc"), a));
+    assert!(!map.insert(Slice("bcd"), b));
+    assert!(!map.insert(Owned(~"cde"), c));
+    assert!(!map.insert(Slice("def"), d));
 
     assert_eq!(map.find_equiv(&("abc")), Some(&a));
     assert_eq!(map.find_equiv(&("bcd")), Some(&b));
@@ -63,13 +62,13 @@ pub fn main() {
     assert_eq!(map.find_equiv(&(~"cde")), Some(&c));
     assert_eq!(map.find_equiv(&(~"def")), Some(&d));
 
-    assert_eq!(map.find_equiv(&SendStrStatic("abc")), Some(&a));
-    assert_eq!(map.find_equiv(&SendStrStatic("bcd")), Some(&b));
-    assert_eq!(map.find_equiv(&SendStrStatic("cde")), Some(&c));
-    assert_eq!(map.find_equiv(&SendStrStatic("def")), Some(&d));
+    assert_eq!(map.find_equiv(&Slice("abc")), Some(&a));
+    assert_eq!(map.find_equiv(&Slice("bcd")), Some(&b));
+    assert_eq!(map.find_equiv(&Slice("cde")), Some(&c));
+    assert_eq!(map.find_equiv(&Slice("def")), Some(&d));
 
-    assert_eq!(map.find_equiv(&SendStrOwned(~"abc")), Some(&a));
-    assert_eq!(map.find_equiv(&SendStrOwned(~"bcd")), Some(&b));
-    assert_eq!(map.find_equiv(&SendStrOwned(~"cde")), Some(&c));
-    assert_eq!(map.find_equiv(&SendStrOwned(~"def")), Some(&d));
+    assert_eq!(map.find_equiv(&Owned(~"abc")), Some(&a));
+    assert_eq!(map.find_equiv(&Owned(~"bcd")), Some(&b));
+    assert_eq!(map.find_equiv(&Owned(~"cde")), Some(&c));
+    assert_eq!(map.find_equiv(&Owned(~"def")), Some(&d));
 }
index 6332d779e5e6d621cd1306ba0a85eff902c76b59..1b7d7bf0b4b570d51f81e9b0973eab844545f4c6 100644 (file)
 use std::cmp::Equal;
 use std::container::{Container, Map, MutableMap};
 use std::default::Default;
-use std::send_str::{SendStr, SendStrOwned, SendStrStatic};
-use std::str::Str;
+use std::str::{Str, SendStr, Owned, Slice};
 use std::to_str::ToStr;
 use self::collections::TreeMap;
 use std::option::Some;
 
 pub fn main() {
     let mut map: TreeMap<SendStr, uint> = TreeMap::new();
-    assert!(map.insert(SendStrStatic("foo"), 42));
-    assert!(!map.insert(SendStrOwned(~"foo"), 42));
-    assert!(!map.insert(SendStrStatic("foo"), 42));
-    assert!(!map.insert(SendStrOwned(~"foo"), 42));
+    assert!(map.insert(Slice("foo"), 42));
+    assert!(!map.insert(Owned(~"foo"), 42));
+    assert!(!map.insert(Slice("foo"), 42));
+    assert!(!map.insert(Owned(~"foo"), 42));
 
-    assert!(!map.insert(SendStrStatic("foo"), 43));
-    assert!(!map.insert(SendStrOwned(~"foo"), 44));
-    assert!(!map.insert(SendStrStatic("foo"), 45));
-    assert!(!map.insert(SendStrOwned(~"foo"), 46));
+    assert!(!map.insert(Slice("foo"), 43));
+    assert!(!map.insert(Owned(~"foo"), 44));
+    assert!(!map.insert(Slice("foo"), 45));
+    assert!(!map.insert(Owned(~"foo"), 46));
 
     let v = 46;
 
-    assert_eq!(map.find(&SendStrOwned(~"foo")), Some(&v));
-    assert_eq!(map.find(&SendStrStatic("foo")), Some(&v));
+    assert_eq!(map.find(&Owned(~"foo")), Some(&v));
+    assert_eq!(map.find(&Slice("foo")), Some(&v));
 
     let (a, b, c, d) = (50, 51, 52, 53);
 
-    assert!(map.insert(SendStrStatic("abc"), a));
-    assert!(map.insert(SendStrOwned(~"bcd"), b));
-    assert!(map.insert(SendStrStatic("cde"), c));
-    assert!(map.insert(SendStrOwned(~"def"), d));
+    assert!(map.insert(Slice("abc"), a));
+    assert!(map.insert(Owned(~"bcd"), b));
+    assert!(map.insert(Slice("cde"), c));
+    assert!(map.insert(Owned(~"def"), d));
 
-    assert!(!map.insert(SendStrStatic("abc"), a));
-    assert!(!map.insert(SendStrOwned(~"bcd"), b));
-    assert!(!map.insert(SendStrStatic("cde"), c));
-    assert!(!map.insert(SendStrOwned(~"def"), d));
+    assert!(!map.insert(Slice("abc"), a));
+    assert!(!map.insert(Owned(~"bcd"), b));
+    assert!(!map.insert(Slice("cde"), c));
+    assert!(!map.insert(Owned(~"def"), d));
 
-    assert!(!map.insert(SendStrOwned(~"abc"), a));
-    assert!(!map.insert(SendStrStatic("bcd"), b));
-    assert!(!map.insert(SendStrOwned(~"cde"), c));
-    assert!(!map.insert(SendStrStatic("def"), d));
+    assert!(!map.insert(Owned(~"abc"), a));
+    assert!(!map.insert(Slice("bcd"), b));
+    assert!(!map.insert(Owned(~"cde"), c));
+    assert!(!map.insert(Slice("def"), d));
 
-    assert_eq!(map.find(&SendStrStatic("abc")), Some(&a));
-    assert_eq!(map.find(&SendStrStatic("bcd")), Some(&b));
-    assert_eq!(map.find(&SendStrStatic("cde")), Some(&c));
-    assert_eq!(map.find(&SendStrStatic("def")), Some(&d));
+    assert_eq!(map.find(&Slice("abc")), Some(&a));
+    assert_eq!(map.find(&Slice("bcd")), Some(&b));
+    assert_eq!(map.find(&Slice("cde")), Some(&c));
+    assert_eq!(map.find(&Slice("def")), Some(&d));
 
-    assert_eq!(map.find(&SendStrOwned(~"abc")), Some(&a));
-    assert_eq!(map.find(&SendStrOwned(~"bcd")), Some(&b));
-    assert_eq!(map.find(&SendStrOwned(~"cde")), Some(&c));
-    assert_eq!(map.find(&SendStrOwned(~"def")), Some(&d));
+    assert_eq!(map.find(&Owned(~"abc")), Some(&a));
+    assert_eq!(map.find(&Owned(~"bcd")), Some(&b));
+    assert_eq!(map.find(&Owned(~"cde")), Some(&c));
+    assert_eq!(map.find(&Owned(~"def")), Some(&d));
 
-    assert!(map.pop(&SendStrStatic("foo")).is_some());
+    assert!(map.pop(&Slice("foo")).is_some());
     assert_eq!(map.move_iter().map(|(k, v)| k.to_str() + v.to_str())
                               .to_owned_vec()
                               .concat(),