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
-12
View File
@@ -310,18 +310,6 @@ fn decode(d: &mut D) -> ~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 {
fn encode(&self, s: &mut S) {
s.emit_f32(*self)
-1
View File
@@ -338,7 +338,6 @@ fn test_to_managed() {
assert_eq!(to_managed::<int>([]), @[]);
assert_eq!(to_managed([true]), @[true]);
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]]);
}
-1
View File
@@ -1167,7 +1167,6 @@ fn fmt(me: &$ty, f: &mut Formatter) {
delegate!( u16 to Unsigned)
delegate!( u32 to Unsigned)
delegate!( u64 to Unsigned)
delegate!(@str to String)
delegate!(~str to String)
delegate!(&'a str to String)
delegate!(bool to Bool)
-13
View File
@@ -604,19 +604,6 @@ fn container_as_str<'a>(&'a self) -> Option<&'a str> {
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] {
#[inline]
fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
-2
View File
@@ -830,7 +830,6 @@ macro_rules! t(
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"], "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!("f")], b!("/e/f"));
t!(v: b!("a/b/c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a/b/c/d/e"));
@@ -940,7 +939,6 @@ macro_rules! t(
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"], "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").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())],
-2
View File
@@ -1610,7 +1610,6 @@ macro_rules! t(
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"], "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!("f")], b!("\\e\\f"));
t!(v: b!("a\\b\\c"), [b!("d").to_owned(), b!("e").to_owned()], b!("a\\b\\c\\d\\e"));
@@ -1755,7 +1754,6 @@ macro_rules! t(
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"], "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").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())],
-3
View File
@@ -183,9 +183,6 @@ fn visit_char(&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
}
+1 -5
View File
@@ -272,10 +272,7 @@ fn visit_char(&mut self) -> bool {
}
fn visit_estr_box(&mut self) -> bool {
self.get::<@str>(|this, s| {
this.writer.write(['@' as u8]);
this.write_escaped_slice(*s);
})
true
}
fn visit_estr_uniq(&mut self) -> bool {
@@ -628,7 +625,6 @@ fn exact_test<T>(t: &T, e:&str) {
exact_test(&false, "false");
exact_test(&1.234, "1.234f64");
exact_test(&(&"hello"), "\"hello\"");
exact_test(&(@"hello"), "@\"hello\"");
exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\"");
exact_test(&(@10), "@10");
-2
View File
@@ -185,7 +185,6 @@ fn test_send_str_traits() {
assert_eq!(s.len(), 5);
assert_eq!(s.as_slice(), "abcde");
assert_eq!(s.to_str(), ~"abcde");
assert!(s.equiv(&@"abcde"));
assert!(s.lt(&SendStrOwned(~"bcdef")));
assert_eq!(SendStrStatic(""), Default::default());
@@ -193,7 +192,6 @@ fn test_send_str_traits() {
assert_eq!(o.len(), 5);
assert_eq!(o.as_slice(), "abcde");
assert_eq!(o.to_str(), ~"abcde");
assert!(o.equiv(&@"abcde"));
assert!(o.lt(&SendStrStatic("bcdef")));
assert_eq!(SendStrOwned(~""), Default::default());
+11 -119
View File
@@ -17,46 +17,35 @@
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
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
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
other functions.
* `@str` - This is a managed string. Similarly to `@T`, this type can be
implicitly copied, and each implicit copy will increment the
reference count to the string. This means that there is no "true
owner" of the string, and the string will be deallocated when the
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.
* `&str` - This is the borrowed string type. This type of string can only be
created from the other kind of string. 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.
```rust
#[feature(managed_boxes)];
fn main() {
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_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
literals. The owned/managed literals correspond to the owned/managed string
types, but the "borrowed literal" is actually more akin to C's concept of a
static string.
From the example above, you can see that rust has 2 different kinds of string
literals. The owned literals correspond to the owned string types, but the
"borrowed literal" is actually more akin to C's concept of a static string.
When a string is declared without a `~` or `@` sigil, then the string is
allocated statically in the rodata of the executable/library. The string then
has the type `&'static str` meaning that the string is valid for the `'static`
When a string is declared without a `~` sigil, then the string is allocated
statically in the rodata of the executable/library. The string then has the
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
inferred from the type, these static strings are not mutable.
@@ -89,11 +78,9 @@ fn main() {
* `~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::transmute;
use char;
@@ -157,16 +144,6 @@ impl<'a> ToStr for &'a str {
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
///
/// # Failure
@@ -1140,11 +1117,6 @@ impl TotalOrd for ~str {
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 {
#[inline]
fn eq(&self, other: & &'a str) -> bool {
@@ -1161,13 +1133,6 @@ fn eq(&self, other: &~str) -> bool {
}
}
impl Eq for @str {
#[inline]
fn eq(&self, other: &@str) -> bool {
eq_slice((*self), (*other))
}
}
impl<'a> TotalEq for &'a str {
#[inline]
fn equals(&self, other: & &'a str) -> bool {
@@ -1182,13 +1147,6 @@ fn equals(&self, other: &~str) -> bool {
}
}
impl TotalEq for @str {
#[inline]
fn equals(&self, other: &@str) -> bool {
eq_slice((*self), (*other))
}
}
impl<'a> Ord for &'a str {
#[inline]
fn lt(&self, other: & &'a str) -> bool { self.cmp(other) == Less }
@@ -1199,21 +1157,11 @@ impl Ord for ~str {
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 {
#[inline]
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 {
#[inline]
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
@@ -1250,16 +1198,6 @@ fn as_slice<'a>(&'a self) -> &'a str {
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 {
#[inline]
fn len(&self) -> uint {
@@ -1272,11 +1210,6 @@ impl Container for ~str {
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 {
/// Remove all content, make the string empty
#[inline]
@@ -1734,9 +1667,6 @@ pub trait StrSlice<'a> {
/// Copy a slice into a new owned 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.
fn to_utf16(&self) -> ~[u16];
@@ -2246,14 +2176,6 @@ fn to_owned(&self) -> ~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] {
let mut u = ~[];
for ch in self.chars() {
@@ -2682,20 +2604,6 @@ fn deep_clone(&self) -> ~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 {
#[inline]
fn from_iterator<T: Iterator<char>>(iterator: &mut T) -> ~str {
@@ -2727,10 +2635,6 @@ impl Default for ~str {
fn default() -> ~str { ~"" }
}
impl Default for @str {
fn default() -> @str { @"" }
}
#[cfg(test)]
mod tests {
use iter::AdditiveIterator;
@@ -3536,12 +3440,6 @@ fn test_escape_default() {
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]
fn test_total_ord() {
"1234".cmp(& &"123") == Greater;
@@ -3584,10 +3482,8 @@ macro_rules! t (
);
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");
}
@@ -3874,7 +3770,6 @@ fn t<S: Default + Str>() {
}
t::<&str>();
t::<@str>();
t::<~str>();
}
@@ -3886,7 +3781,6 @@ fn sum_len<S: Container>(v: &[S]) -> uint {
let s = ~"01234";
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([s.as_slice()]));
}
@@ -3957,8 +3851,6 @@ fn test_to_send_str() {
fn test_from_str() {
let owned: Option<~str> = from_str(&"string");
assert_eq!(owned, Some(~"string"));
let managed: Option<@str> = from_str(&"string");
assert_eq!(managed, Some(@"string"));
}
}
-7
View File
@@ -288,13 +288,6 @@ fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
}
}
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> {
#[inline]
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
-1
View File
@@ -195,7 +195,6 @@ fn test_simple_types() {
assert_eq!(false.to_str(), ~"false");
assert_eq!(().to_str(), ~"()");
assert_eq!((~"hi").to_str(), ~"hi");
assert_eq!((@"hi").to_str(), ~"hi");
}
#[test]
-1
View File
@@ -59,7 +59,6 @@ impl<T> Repr<*Box<T>> for @T {}
impl<T> Repr<*Box<Vec<T>>> for @[T] {}
impl<T> Repr<*Vec<T>> for ~[T] {}
impl Repr<*String> for ~str {}
impl Repr<*Box<String>> for @str {}
// sure would be nice to have this
// impl<T> Repr<*Vec<T>> for ~[T] {}