libextra: Remove @str from all the libraries

This commit is contained in:
Patrick Walton
2014-01-31 16:50:45 -08:00
committed by Huon Wilson
parent 4dbcf800d5
commit 449a7a817f
13 changed files with 12 additions and 169 deletions

View File

@@ -310,18 +310,6 @@ impl<D:Decoder> Decodable<D> for ~str {
} }
} }
impl<S:Encoder> Encodable<S> for @str {
fn encode(&self, s: &mut S) {
s.emit_str(*self)
}
}
impl<D:Decoder> Decodable<D> for @str {
fn decode(d: &mut D) -> @str {
d.read_str().to_managed()
}
}
impl<S:Encoder> Encodable<S> for f32 { impl<S:Encoder> Encodable<S> for f32 {
fn encode(&self, s: &mut S) { fn encode(&self, s: &mut S) {
s.emit_f32(*self) s.emit_f32(*self)

View File

@@ -338,7 +338,6 @@ mod test {
assert_eq!(to_managed::<int>([]), @[]); assert_eq!(to_managed::<int>([]), @[]);
assert_eq!(to_managed([true]), @[true]); assert_eq!(to_managed([true]), @[true]);
assert_eq!(to_managed([1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]); assert_eq!(to_managed([1, 2, 3, 4, 5]), @[1, 2, 3, 4, 5]);
assert_eq!(to_managed([@"abc", @"123"]), @[@"abc", @"123"]);
assert_eq!(to_managed([@[42]]), @[@[42]]); assert_eq!(to_managed([@[42]]), @[@[42]]);
} }

View File

@@ -1167,7 +1167,6 @@ delegate!( u8 to Unsigned)
delegate!( u16 to Unsigned) delegate!( u16 to Unsigned)
delegate!( u32 to Unsigned) delegate!( u32 to Unsigned)
delegate!( u64 to Unsigned) delegate!( u64 to Unsigned)
delegate!(@str to String)
delegate!(~str to String) delegate!(~str to String)
delegate!(&'a str to String) delegate!(&'a str to String)
delegate!(bool to Bool) delegate!(bool to Bool)

View File

@@ -604,19 +604,6 @@ impl BytesContainer for ~str {
fn is_str(_: Option<~str>) -> bool { true } fn is_str(_: Option<~str>) -> bool { true }
} }
impl BytesContainer for @str {
#[inline]
fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
self.as_bytes()
}
#[inline]
fn container_as_str<'a>(&'a self) -> Option<&'a str> {
Some(self.as_slice())
}
#[inline]
fn is_str(_: Option<@str>) -> bool { true }
}
impl<'a> BytesContainer for &'a [u8] { impl<'a> BytesContainer for &'a [u8] {
#[inline] #[inline]
fn container_as_bytes<'a>(&'a self) -> &'a [u8] { fn container_as_bytes<'a>(&'a self) -> &'a [u8] {

View File

@@ -830,7 +830,6 @@ mod tests {
t!(s: "a/b/c", ["d", "/e"], "/e"); t!(s: "a/b/c", ["d", "/e"], "/e");
t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f");
t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e");
t!(s: "a/b/c", [@"d", @"e"], "a/b/c/d/e");
t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e"));
t!(v: b!("a/b/c"), [b!("d"), b!("/e"), b!("f")], b!("/e/f")); t!(v: b!("a/b/c"), [b!("d"), b!("/e"), b!("f")], b!("/e/f"));
t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e"));
@@ -940,7 +939,6 @@ mod tests {
t!(s: "a/b/c", ["..", "d"], "a/b/d"); t!(s: "a/b/c", ["..", "d"], "a/b/d");
t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f");
t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e");
t!(s: "a/b/c", [@"d", @"e"], "a/b/c/d/e");
t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e"));
t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e"));
t!(v: b!("a/b/c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], t!(v: b!("a/b/c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())],

View File

@@ -1610,7 +1610,6 @@ mod tests {
t!(s: "a\\b\\c", ["d", "\\e"], "\\e"); t!(s: "a\\b\\c", ["d", "\\e"], "\\e");
t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f");
t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e");
t!(s: "a\\b\\c", [@"d", @"e"], "a\\b\\c\\d\\e");
t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e"));
t!(v: b!("a\\b\\c"), [b!("d"), b!("\\e"), b!("f")], b!("\\e\\f")); t!(v: b!("a\\b\\c"), [b!("d"), b!("\\e"), b!("f")], b!("\\e\\f"));
t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e"));
@@ -1755,7 +1754,6 @@ mod tests {
t!(s: "a\\b\\c", ["..", "d"], "a\\b\\d"); t!(s: "a\\b\\c", ["..", "d"], "a\\b\\d");
t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f");
t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e");
t!(s: "a\\b\\c", [@"d", @"e"], "a\\b\\c\\d\\e");
t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e"));
t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e"));
t!(v: b!("a\\b\\c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())], t!(v: b!("a\\b\\c"), [to_man(b!("d").to_owned()), to_man(b!("e").to_owned())],

View File

@@ -183,9 +183,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
} }
fn visit_estr_box(&mut self) -> bool { fn visit_estr_box(&mut self) -> bool {
self.align_to::<@str>();
if ! self.inner.visit_estr_box() { return false; }
self.bump_past::<@str>();
true true
} }

View File

@@ -272,10 +272,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
} }
fn visit_estr_box(&mut self) -> bool { fn visit_estr_box(&mut self) -> bool {
self.get::<@str>(|this, s| { true
this.writer.write(['@' as u8]);
this.write_escaped_slice(*s);
})
} }
fn visit_estr_uniq(&mut self) -> bool { fn visit_estr_uniq(&mut self) -> bool {
@@ -628,7 +625,6 @@ fn test_repr() {
exact_test(&false, "false"); exact_test(&false, "false");
exact_test(&1.234, "1.234f64"); exact_test(&1.234, "1.234f64");
exact_test(&(&"hello"), "\"hello\""); exact_test(&(&"hello"), "\"hello\"");
exact_test(&(@"hello"), "@\"hello\"");
exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\""); exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\"");
exact_test(&(@10), "@10"); exact_test(&(@10), "@10");

View File

@@ -185,7 +185,6 @@ mod tests {
assert_eq!(s.len(), 5); assert_eq!(s.len(), 5);
assert_eq!(s.as_slice(), "abcde"); assert_eq!(s.as_slice(), "abcde");
assert_eq!(s.to_str(), ~"abcde"); assert_eq!(s.to_str(), ~"abcde");
assert!(s.equiv(&@"abcde"));
assert!(s.lt(&SendStrOwned(~"bcdef"))); assert!(s.lt(&SendStrOwned(~"bcdef")));
assert_eq!(SendStrStatic(""), Default::default()); assert_eq!(SendStrStatic(""), Default::default());
@@ -193,7 +192,6 @@ mod tests {
assert_eq!(o.len(), 5); assert_eq!(o.len(), 5);
assert_eq!(o.as_slice(), "abcde"); assert_eq!(o.as_slice(), "abcde");
assert_eq!(o.to_str(), ~"abcde"); assert_eq!(o.to_str(), ~"abcde");
assert!(o.equiv(&@"abcde"));
assert!(o.lt(&SendStrStatic("bcdef"))); assert!(o.lt(&SendStrStatic("bcdef")));
assert_eq!(SendStrOwned(~""), Default::default()); assert_eq!(SendStrOwned(~""), Default::default());

View File

@@ -17,46 +17,35 @@ Unicode string manipulation (`str` type)
Rust's string type is one of the core primitive types of the language. While Rust's string type is one of the core primitive types of the language. While
represented by the name `str`, the name `str` is not actually a valid type in represented by the name `str`, the name `str` is not actually a valid type in
Rust. Each string must also be decorated with its ownership. This means that Rust. Each string must also be decorated with its ownership. This means that
there are three common kinds of strings in rust: there are two common kinds of strings in rust:
* `~str` - This is an owned string. This type obeys all of the normal semantics * `~str` - This is an owned string. This type obeys all of the normal semantics
of the `~T` types, meaning that it has one, and only one, owner. This of the `~T` types, meaning that it has one, and only one, owner. This
type cannot be implicitly copied, and is moved out of when passed to type cannot be implicitly copied, and is moved out of when passed to
other functions. other functions.
* `@str` - This is a managed string. Similarly to `@T`, this type can be * `&str` - This is the borrowed string type. This type of string can only be
implicitly copied, and each implicit copy will increment the created from the other kind of string. As the name "borrowed"
reference count to the string. This means that there is no "true implies, this type of string is owned elsewhere, and this string
owner" of the string, and the string will be deallocated when the cannot be moved out of.
reference count reaches 0.
* `&str` - Finally, this is the borrowed string type. This type of string can
only be created from one of the other two kinds of strings. As the
name "borrowed" implies, this type of string is owned elsewhere, and
this string cannot be moved out of.
As an example, here's a few different kinds of strings. As an example, here's a few different kinds of strings.
```rust ```rust
#[feature(managed_boxes)];
fn main() { fn main() {
let owned_string = ~"I am an owned string"; let owned_string = ~"I am an owned string";
let managed_string = @"This string is garbage-collected";
let borrowed_string1 = "This string is borrowed with the 'static lifetime"; let borrowed_string1 = "This string is borrowed with the 'static lifetime";
let borrowed_string2: &str = owned_string; // owned strings can be borrowed let borrowed_string2: &str = owned_string; // owned strings can be borrowed
let borrowed_string3: &str = managed_string; // managed strings can also be borrowed
} }
``` ```
From the example above, you can see that rust has 3 different kinds of string From the example above, you can see that rust has 2 different kinds of string
literals. The owned/managed literals correspond to the owned/managed string literals. The owned literals correspond to the owned string types, but the
types, but the "borrowed literal" is actually more akin to C's concept of a "borrowed literal" is actually more akin to C's concept of a static string.
static string.
When a string is declared without a `~` or `@` sigil, then the string is When a string is declared without a `~` sigil, then the string is allocated
allocated statically in the rodata of the executable/library. The string then statically in the rodata of the executable/library. The string then has the
has the type `&'static str` meaning that the string is valid for the `'static` type `&'static str` meaning that the string is valid for the `'static`
lifetime, otherwise known as the lifetime of the entire program. As can be lifetime, otherwise known as the lifetime of the entire program. As can be
inferred from the type, these static strings are not mutable. inferred from the type, these static strings are not mutable.
@@ -89,11 +78,9 @@ The actual representation of strings have direct mappings to vectors:
* `~str` is the same as `~[u8]` * `~str` is the same as `~[u8]`
* `&str` is the same as `&[u8]` * `&str` is the same as `&[u8]`
* `@str` is the same as `@[u8]`
*/ */
use at_vec;
use cast; use cast;
use cast::transmute; use cast::transmute;
use char; use char;
@@ -157,16 +144,6 @@ impl<'a> ToStr for &'a str {
fn to_str(&self) -> ~str { self.to_owned() } fn to_str(&self) -> ~str { self.to_owned() }
} }
impl ToStr for @str {
#[inline]
fn to_str(&self) -> ~str { self.to_owned() }
}
impl<'a> FromStr for @str {
#[inline]
fn from_str(s: &str) -> Option<@str> { Some(s.to_managed()) }
}
/// Convert a byte to a UTF-8 string /// Convert a byte to a UTF-8 string
/// ///
/// # Failure /// # Failure
@@ -1140,11 +1117,6 @@ pub mod traits {
fn cmp(&self, other: &~str) -> Ordering { self.as_slice().cmp(&other.as_slice()) } fn cmp(&self, other: &~str) -> Ordering { self.as_slice().cmp(&other.as_slice()) }
} }
impl TotalOrd for @str {
#[inline]
fn cmp(&self, other: &@str) -> Ordering { self.as_slice().cmp(&other.as_slice()) }
}
impl<'a> Eq for &'a str { impl<'a> Eq for &'a str {
#[inline] #[inline]
fn eq(&self, other: & &'a str) -> bool { fn eq(&self, other: & &'a str) -> bool {
@@ -1161,13 +1133,6 @@ pub mod traits {
} }
} }
impl Eq for @str {
#[inline]
fn eq(&self, other: &@str) -> bool {
eq_slice((*self), (*other))
}
}
impl<'a> TotalEq for &'a str { impl<'a> TotalEq for &'a str {
#[inline] #[inline]
fn equals(&self, other: & &'a str) -> bool { fn equals(&self, other: & &'a str) -> bool {
@@ -1182,13 +1147,6 @@ pub mod traits {
} }
} }
impl TotalEq for @str {
#[inline]
fn equals(&self, other: &@str) -> bool {
eq_slice((*self), (*other))
}
}
impl<'a> Ord for &'a str { impl<'a> Ord for &'a str {
#[inline] #[inline]
fn lt(&self, other: & &'a str) -> bool { self.cmp(other) == Less } fn lt(&self, other: & &'a str) -> bool { self.cmp(other) == Less }
@@ -1199,21 +1157,11 @@ pub mod traits {
fn lt(&self, other: &~str) -> bool { self.cmp(other) == Less } fn lt(&self, other: &~str) -> bool { self.cmp(other) == Less }
} }
impl Ord for @str {
#[inline]
fn lt(&self, other: &@str) -> bool { self.cmp(other) == Less }
}
impl<'a, S: Str> Equiv<S> for &'a str { impl<'a, S: Str> Equiv<S> for &'a str {
#[inline] #[inline]
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
} }
impl<'a, S: Str> Equiv<S> for @str {
#[inline]
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
}
impl<'a, S: Str> Equiv<S> for ~str { impl<'a, S: Str> Equiv<S> for ~str {
#[inline] #[inline]
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
@@ -1250,16 +1198,6 @@ impl<'a> Str for ~str {
fn into_owned(self) -> ~str { self } fn into_owned(self) -> ~str { self }
} }
impl<'a> Str for @str {
#[inline]
fn as_slice<'a>(&'a self) -> &'a str {
let s: &'a str = *self; s
}
#[inline]
fn into_owned(self) -> ~str { self.to_owned() }
}
impl<'a> Container for &'a str { impl<'a> Container for &'a str {
#[inline] #[inline]
fn len(&self) -> uint { fn len(&self) -> uint {
@@ -1272,11 +1210,6 @@ impl Container for ~str {
fn len(&self) -> uint { self.as_slice().len() } fn len(&self) -> uint { self.as_slice().len() }
} }
impl Container for @str {
#[inline]
fn len(&self) -> uint { self.as_slice().len() }
}
impl Mutable for ~str { impl Mutable for ~str {
/// Remove all content, make the string empty /// Remove all content, make the string empty
#[inline] #[inline]
@@ -1734,9 +1667,6 @@ pub trait StrSlice<'a> {
/// Copy a slice into a new owned str. /// Copy a slice into a new owned str.
fn to_owned(&self) -> ~str; fn to_owned(&self) -> ~str;
/// Copy a slice into a new managed str.
fn to_managed(&self) -> @str;
/// Converts to a vector of `u16` encoded as UTF-16. /// Converts to a vector of `u16` encoded as UTF-16.
fn to_utf16(&self) -> ~[u16]; fn to_utf16(&self) -> ~[u16];
@@ -2246,14 +2176,6 @@ impl<'a> StrSlice<'a> for &'a str {
} }
} }
#[inline]
fn to_managed(&self) -> @str {
unsafe {
let v: *&[u8] = cast::transmute(self);
cast::transmute(at_vec::to_managed(*v))
}
}
fn to_utf16(&self) -> ~[u16] { fn to_utf16(&self) -> ~[u16] {
let mut u = ~[]; let mut u = ~[];
for ch in self.chars() { for ch in self.chars() {
@@ -2682,20 +2604,6 @@ impl DeepClone for ~str {
} }
} }
impl Clone for @str {
#[inline]
fn clone(&self) -> @str {
*self
}
}
impl DeepClone for @str {
#[inline]
fn deep_clone(&self) -> @str {
*self
}
}
impl FromIterator<char> for ~str { impl FromIterator<char> for ~str {
#[inline] #[inline]
fn from_iterator<T: Iterator<char>>(iterator: &mut T) -> ~str { fn from_iterator<T: Iterator<char>>(iterator: &mut T) -> ~str {
@@ -2727,10 +2635,6 @@ impl Default for ~str {
fn default() -> ~str { ~"" } fn default() -> ~str { ~"" }
} }
impl Default for @str {
fn default() -> @str { @"" }
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use iter::AdditiveIterator; use iter::AdditiveIterator;
@@ -3536,12 +3440,6 @@ mod tests {
assert_eq!("\U0001d4ea\r".escape_default(), ~"\\U0001d4ea\\r"); assert_eq!("\U0001d4ea\r".escape_default(), ~"\\U0001d4ea\\r");
} }
#[test]
fn test_to_managed() {
assert_eq!("abc".to_managed(), @"abc");
assert_eq!("abcdef".slice(1, 5).to_managed(), @"bcde");
}
#[test] #[test]
fn test_total_ord() { fn test_total_ord() {
"1234".cmp(& &"123") == Greater; "1234".cmp(& &"123") == Greater;
@@ -3584,10 +3482,8 @@ mod tests {
); );
t!("foo", "bar", "foobar"); t!("foo", "bar", "foobar");
t!("foo", @"bar", "foobar");
t!("foo", ~"bar", "foobar"); t!("foo", ~"bar", "foobar");
t!("ศไทย中", "华Việt Nam", "ศไทย中华Việt Nam"); t!("ศไทย中", "华Việt Nam", "ศไทย中华Việt Nam");
t!("ศไทย中", @"华Việt Nam", "ศไทย中华Việt Nam");
t!("ศไทย中", ~"华Việt Nam", "ศไทย中华Việt Nam"); t!("ศไทย中", ~"华Việt Nam", "ศไทย中华Việt Nam");
} }
@@ -3874,7 +3770,6 @@ mod tests {
} }
t::<&str>(); t::<&str>();
t::<@str>();
t::<~str>(); t::<~str>();
} }
@@ -3886,7 +3781,6 @@ mod tests {
let s = ~"01234"; let s = ~"01234";
assert_eq!(5, sum_len(["012", "", "34"])); assert_eq!(5, sum_len(["012", "", "34"]));
assert_eq!(5, sum_len([@"01", @"2", @"34", @""]));
assert_eq!(5, sum_len([~"01", ~"2", ~"34", ~""])); assert_eq!(5, sum_len([~"01", ~"2", ~"34", ~""]));
assert_eq!(5, sum_len([s.as_slice()])); assert_eq!(5, sum_len([s.as_slice()]));
} }
@@ -3957,8 +3851,6 @@ mod tests {
fn test_from_str() { fn test_from_str() {
let owned: Option<~str> = from_str(&"string"); let owned: Option<~str> = from_str(&"string");
assert_eq!(owned, Some(~"string")); assert_eq!(owned, Some(~"string"));
let managed: Option<@str> = from_str(&"string");
assert_eq!(managed, Some(@"string"));
} }
} }

View File

@@ -288,13 +288,6 @@ impl IterBytes for ~str {
} }
} }
impl IterBytes for @str {
#[inline]
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
self.as_slice().iter_bytes(lsb0, f)
}
}
impl<A:IterBytes> IterBytes for Option<A> { impl<A:IterBytes> IterBytes for Option<A> {
#[inline] #[inline]
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {

View File

@@ -195,7 +195,6 @@ mod tests {
assert_eq!(false.to_str(), ~"false"); assert_eq!(false.to_str(), ~"false");
assert_eq!(().to_str(), ~"()"); assert_eq!(().to_str(), ~"()");
assert_eq!((~"hi").to_str(), ~"hi"); assert_eq!((~"hi").to_str(), ~"hi");
assert_eq!((@"hi").to_str(), ~"hi");
} }
#[test] #[test]

View File

@@ -59,7 +59,6 @@ impl<T> Repr<*Box<T>> for @T {}
impl<T> Repr<*Box<Vec<T>>> for @[T] {} impl<T> Repr<*Box<Vec<T>>> for @[T] {}
impl<T> Repr<*Vec<T>> for ~[T] {} impl<T> Repr<*Vec<T>> for ~[T] {}
impl Repr<*String> for ~str {} impl Repr<*String> for ~str {}
impl Repr<*Box<String>> for @str {}
// sure would be nice to have this // sure would be nice to have this
// impl<T> Repr<*Vec<T>> for ~[T] {} // impl<T> Repr<*Vec<T>> for ~[T] {}