about summary refs log tree commit diff
path: root/src/libserialize
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-12-22 12:45:54 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-12-22 12:45:54 -0800
commit9b99436152e3fbcf1dc2a1fd343f57237dc27f23 (patch)
tree8119d5307ca14d2ec3cd9ac429ff1819451ed6a0 /src/libserialize
parent2f55a9db0de8b2a2d72c7139eae38272d4d8cf41 (diff)
parent082bfde412176249dc7328e771a2a15d202824cf (diff)
downloadrust-9b99436152e3fbcf1dc2a1fd343f57237dc27f23.tar.gz
rust-9b99436152e3fbcf1dc2a1fd343f57237dc27f23.zip
rollup merge of #19741: alexcrichton/stabilize-str
This commit starts out by consolidating all `str` extension traits into one
`StrExt` trait to be included in the prelude. This means that
`UnicodeStrPrelude`, `StrPrelude`, and `StrAllocating` have all been merged into
one `StrExt` exported by the standard library. Some functionality is currently
duplicated with the `StrExt` present in libcore.

This commit also currently avoids any methods which require any form of pattern
to operate. These functions will be stabilized via a separate RFC.

Next, stability of methods and structures are as follows:

Stable

* from_utf8_unchecked
* CowString - after moving to std::string
* StrExt::as_bytes
* StrExt::as_ptr
* StrExt::bytes/Bytes - also made a struct instead of a typedef
* StrExt::char_indices/CharIndices - CharOffsets was renamed
* StrExt::chars/Chars
* StrExt::is_empty
* StrExt::len
* StrExt::lines/Lines
* StrExt::lines_any/LinesAny
* StrExt::slice_unchecked
* StrExt::trim
* StrExt::trim_left
* StrExt::trim_right
* StrExt::words/Words - also made a struct instead of a typedef

Unstable

* from_utf8 - the error type was changed to a `Result`, but the error type has
              yet to prove itself
* from_c_str - this function will be handled by the c_str RFC
* FromStr - this trait will have an associated error type eventually
* StrExt::escape_default - needs iterators at least, unsure if it should make
                           the cut
* StrExt::escape_unicode - needs iterators at least, unsure if it should make
                           the cut
* StrExt::slice_chars - this function has yet to prove itself
* StrExt::slice_shift_char - awaiting conventions about slicing and shifting
* StrExt::graphemes/Graphemes - this functionality may only be in libunicode
* StrExt::grapheme_indices/GraphemeIndices - this functionality may only be in
                                             libunicode
* StrExt::width - this functionality may only be in libunicode
* StrExt::utf16_units - this functionality may only be in libunicode
* StrExt::nfd_chars - this functionality may only be in libunicode
* StrExt::nfkd_chars - this functionality may only be in libunicode
* StrExt::nfc_chars - this functionality may only be in libunicode
* StrExt::nfkc_chars - this functionality may only be in libunicode
* StrExt::is_char_boundary - naming is uncertain with container conventions
* StrExt::char_range_at - naming is uncertain with container conventions
* StrExt::char_range_at_reverse - naming is uncertain with container conventions
* StrExt::char_at - naming is uncertain with container conventions
* StrExt::char_at_reverse - naming is uncertain with container conventions
* StrVector::concat - this functionality may be replaced with iterators, but
                      it's not certain at this time
* StrVector::connect - as with concat, may be deprecated in favor of iterators

Deprecated

* StrAllocating and UnicodeStrPrelude have been merged into StrExit
* eq_slice - compiler implementation detail
* from_str - use the inherent parse() method
* is_utf8 - call from_utf8 instead
* replace - call the method instead
* truncate_utf16_at_nul - this is an implementation detail of windows and does
                          not need to be exposed.
* utf8_char_width - moved to libunicode
* utf16_items - moved to libunicode
* is_utf16 - moved to libunicode
* Utf16Items - moved to libunicode
* Utf16Item - moved to libunicode
* Utf16Encoder - moved to libunicode
* AnyLines - renamed to LinesAny and made a struct
* SendStr - use CowString<'static> instead
* str::raw - all functionality is deprecated
* StrExt::into_string - call to_string() instead
* StrExt::repeat - use iterators instead
* StrExt::char_len - use .chars().count() instead
* StrExt::is_alphanumeric - use .chars().all(..)
* StrExt::is_whitespace - use .chars().all(..)

Pending deprecation -- while slicing syntax is being worked out, these methods
are all #[unstable]

* Str - while currently used for generic programming, this trait will be
        replaced with one of [], deref coercions, or a generic conversion trait.
* StrExt::slice - use slicing syntax instead
* StrExt::slice_to - use slicing syntax instead
* StrExt::slice_from - use slicing syntax instead
* StrExt::lev_distance - deprecated with no replacement

Awaiting stabilization due to patterns and/or matching

* StrExt::contains
* StrExt::contains_char
* StrExt::split
* StrExt::splitn
* StrExt::split_terminator
* StrExt::rsplitn
* StrExt::match_indices
* StrExt::split_str
* StrExt::starts_with
* StrExt::ends_with
* StrExt::trim_chars
* StrExt::trim_left_chars
* StrExt::trim_right_chars
* StrExt::find
* StrExt::rfind
* StrExt::find_str
* StrExt::subslice_offset
Diffstat (limited to 'src/libserialize')
-rw-r--r--src/libserialize/json.rs192
-rw-r--r--src/libserialize/lib.rs1
-rw-r--r--src/libserialize/serialize.rs4
3 files changed, 99 insertions, 98 deletions
diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs
index 3181e28a121..c4f071994dc 100644
--- a/src/libserialize/json.rs
+++ b/src/libserialize/json.rs
@@ -202,10 +202,11 @@ use std::collections::{HashMap, BTreeMap};
 use std::{char, f64, fmt, io, num, str};
 use std::mem::{swap, transmute};
 use std::num::{Float, FPNaN, FPInfinite, Int};
-use std::str::{FromStr, ScalarValue};
+use std::str::{FromStr};
 use std::string;
-use std::vec::Vec;
 use std::ops;
+use unicode::str as unicode_str;
+use unicode::str::Utf16Item;
 
 use Encodable;
 
@@ -1001,7 +1002,7 @@ impl Json {
     /// Returns None otherwise.
     pub fn as_string<'a>(&'a self) -> Option<&'a str> {
         match *self {
-            Json::String(ref s) => Some(s.as_slice()),
+            Json::String(ref s) => Some(s[]),
             _ => None
         }
     }
@@ -1585,8 +1586,8 @@ impl<T: Iterator<char>> Parser<T> {
                             }
 
                             let buf = [n1, try!(self.decode_hex_escape())];
-                            match str::utf16_items(buf.as_slice()).next() {
-                                Some(ScalarValue(c)) => res.push(c),
+                            match unicode_str::utf16_items(&buf).next() {
+                                Some(Utf16Item::ScalarValue(c)) => res.push(c),
                                 _ => return self.error(LoneLeadingSurrogateInHexEscape),
                             }
                         }
@@ -1934,7 +1935,7 @@ pub fn from_reader(rdr: &mut io::Reader) -> Result<Json, BuilderError> {
         Ok(c)  => c,
         Err(e) => return Err(io_error_to_error(e))
     };
-    let s = match str::from_utf8(contents.as_slice()) {
+    let s = match str::from_utf8(contents.as_slice()).ok() {
         Some(s) => s,
         _       => return Err(SyntaxError(NotUtf8, 0, 0))
     };
@@ -1970,7 +1971,7 @@ macro_rules! expect {
     ($e:expr, Null) => ({
         match $e {
             Json::Null => Ok(()),
-            other => Err(ExpectedError("Null".into_string(),
+            other => Err(ExpectedError("Null".to_string(),
                                        format!("{}", other)))
         }
     });
@@ -1991,20 +1992,20 @@ macro_rules! read_primitive {
             match self.pop() {
                 Json::I64(f) => match num::cast(f) {
                     Some(f) => Ok(f),
-                    None => Err(ExpectedError("Number".into_string(), format!("{}", f))),
+                    None => Err(ExpectedError("Number".to_string(), format!("{}", f))),
                 },
                 Json::U64(f) => match num::cast(f) {
                     Some(f) => Ok(f),
-                    None => Err(ExpectedError("Number".into_string(), format!("{}", f))),
+                    None => Err(ExpectedError("Number".to_string(), format!("{}", f))),
                 },
-                Json::F64(f) => Err(ExpectedError("Integer".into_string(), format!("{}", f))),
+                Json::F64(f) => Err(ExpectedError("Integer".to_string(), format!("{}", f))),
                 // re: #12967.. a type w/ numeric keys (ie HashMap<uint, V> etc)
                 // is going to have a string here, as per JSON spec.
                 Json::String(s) => match std::str::from_str(s.as_slice()) {
                     Some(f) => Ok(f),
-                    None => Err(ExpectedError("Number".into_string(), s)),
+                    None => Err(ExpectedError("Number".to_string(), s)),
                 },
-                value => Err(ExpectedError("Number".into_string(), format!("{}", value))),
+                value => Err(ExpectedError("Number".to_string(), format!("{}", value))),
             }
         }
     }
@@ -2036,13 +2037,13 @@ impl ::Decoder<DecoderError> for Decoder {
             Json::String(s) => {
                 // re: #12967.. a type w/ numeric keys (ie HashMap<uint, V> etc)
                 // is going to have a string here, as per JSON spec.
-                match std::str::from_str(s.as_slice()) {
+                match s.parse() {
                     Some(f) => Ok(f),
-                    None => Err(ExpectedError("Number".into_string(), s)),
+                    None => Err(ExpectedError("Number".to_string(), s)),
                 }
             },
             Json::Null => Ok(f64::NAN),
-            value => Err(ExpectedError("Number".into_string(), format!("{}", value)))
+            value => Err(ExpectedError("Number".to_string(), format!("{}", value)))
         }
     }
 
@@ -2060,7 +2061,7 @@ impl ::Decoder<DecoderError> for Decoder {
                 _ => ()
             }
         }
-        Err(ExpectedError("single character string".into_string(), format!("{}", s)))
+        Err(ExpectedError("single character string".to_string(), format!("{}", s)))
     }
 
     fn read_str(&mut self) -> DecodeResult<string::String> {
@@ -2080,36 +2081,35 @@ impl ::Decoder<DecoderError> for Decoder {
         let name = match self.pop() {
             Json::String(s) => s,
             Json::Object(mut o) => {
-                let n = match o.remove(&"variant".into_string()) {
+                let n = match o.remove(&"variant".to_string()) {
                     Some(Json::String(s)) => s,
                     Some(val) => {
-                        return Err(ExpectedError("String".into_string(), format!("{}", val)))
+                        return Err(ExpectedError("String".to_string(), format!("{}", val)))
                     }
                     None => {
-                        return Err(MissingFieldError("variant".into_string()))
+                        return Err(MissingFieldError("variant".to_string()))
                     }
                 };
-                match o.remove(&"fields".into_string()) {
+                match o.remove(&"fields".to_string()) {
                     Some(Json::Array(l)) => {
                         for field in l.into_iter().rev() {
                             self.stack.push(field);
                         }
                     },
                     Some(val) => {
-                        return Err(ExpectedError("Array".into_string(), format!("{}", val)))
+                        return Err(ExpectedError("Array".to_string(), format!("{}", val)))
                     }
                     None => {
-                        return Err(MissingFieldError("fields".into_string()))
+                        return Err(MissingFieldError("fields".to_string()))
                     }
                 }
                 n
             }
             json => {
-                return Err(ExpectedError("String or Object".into_string(), format!("{}", json)))
+                return Err(ExpectedError("String or Object".to_string(), format!("{}", json)))
             }
         };
-        let idx = match names.iter()
-                             .position(|n| str::eq_slice(*n, name.as_slice())) {
+        let idx = match names.iter().position(|n| *n == name[]) {
             Some(idx) => idx,
             None => return Err(UnknownVariantError(name))
         };
@@ -2319,7 +2319,7 @@ impl ToJson for bool {
 }
 
 impl ToJson for str {
-    fn to_json(&self) -> Json { Json::String(self.into_string()) }
+    fn to_json(&self) -> Json { Json::String(self.to_string()) }
 }
 
 impl ToJson for string::String {
@@ -2450,9 +2450,9 @@ mod tests {
     #[test]
     fn test_decode_option_malformed() {
         check_err::<OptionData>("{ \"opt\": [] }",
-                                ExpectedError("Number".into_string(), "[]".into_string()));
+                                ExpectedError("Number".to_string(), "[]".to_string()));
         check_err::<OptionData>("{ \"opt\": false }",
-                                ExpectedError("Number".into_string(), "false".into_string()));
+                                ExpectedError("Number".to_string(), "false".to_string()));
     }
 
     #[deriving(PartialEq, Encodable, Decodable, Show)]
@@ -2538,11 +2538,11 @@ mod tests {
 
     #[test]
     fn test_write_str() {
-        assert_eq!(String("".into_string()).to_string(), "\"\"");
-        assert_eq!(String("".into_string()).to_pretty_str(), "\"\"");
+        assert_eq!(String("".to_string()).to_string(), "\"\"");
+        assert_eq!(String("".to_string()).to_pretty_str(), "\"\"");
 
-        assert_eq!(String("homura".into_string()).to_string(), "\"homura\"");
-        assert_eq!(String("madoka".into_string()).to_pretty_str(), "\"madoka\"");
+        assert_eq!(String("homura".to_string()).to_string(), "\"homura\"");
+        assert_eq!(String("madoka".to_string()).to_pretty_str(), "\"madoka\"");
     }
 
     #[test]
@@ -2571,7 +2571,7 @@ mod tests {
         let long_test_array = Array(vec![
             Boolean(false),
             Null,
-            Array(vec![String("foo\nbar".into_string()), F64(3.5)])]);
+            Array(vec![String("foo\nbar".to_string()), F64(3.5)])]);
 
         assert_eq!(long_test_array.to_string(),
             "[false,null,[\"foo\\nbar\",3.5]]");
@@ -2596,12 +2596,12 @@ mod tests {
 
         assert_eq!(
             mk_object(&[
-                ("a".into_string(), Boolean(true))
+                ("a".to_string(), Boolean(true))
             ]).to_string(),
             "{\"a\":true}"
         );
         assert_eq!(
-            mk_object(&[("a".into_string(), Boolean(true))]).to_pretty_str(),
+            mk_object(&[("a".to_string(), Boolean(true))]).to_pretty_str(),
             "\
             {\n  \
                 \"a\": true\n\
@@ -2609,9 +2609,9 @@ mod tests {
         );
 
         let complex_obj = mk_object(&[
-                ("b".into_string(), Array(vec![
-                    mk_object(&[("c".into_string(), String("\x0c\r".into_string()))]),
-                    mk_object(&[("d".into_string(), String("".into_string()))])
+                ("b".to_string(), Array(vec![
+                    mk_object(&[("c".to_string(), String("\x0c\r".to_string()))]),
+                    mk_object(&[("d".to_string(), String("".to_string()))])
                 ]))
             ]);
 
@@ -2640,10 +2640,10 @@ mod tests {
         );
 
         let a = mk_object(&[
-            ("a".into_string(), Boolean(true)),
-            ("b".into_string(), Array(vec![
-                mk_object(&[("c".into_string(), String("\x0c\r".into_string()))]),
-                mk_object(&[("d".into_string(), String("".into_string()))])
+            ("a".to_string(), Boolean(true)),
+            ("b".to_string(), Array(vec![
+                mk_object(&[("c".to_string(), String("\x0c\r".to_string()))]),
+                mk_object(&[("d".to_string(), String("".to_string()))])
             ]))
         ]);
 
@@ -2678,7 +2678,7 @@ mod tests {
             "\"Dog\""
         );
 
-        let animal = Frog("Henry".into_string(), 349);
+        let animal = Frog("Henry".to_string(), 349);
         assert_eq!(
             with_str_writer(|writer| {
                 let mut encoder = Encoder::new(writer);
@@ -2731,7 +2731,7 @@ mod tests {
     fn test_write_char() {
         check_encoder_for_simple!('a', "\"a\"");
         check_encoder_for_simple!('\t', "\"\\t\"");
-        check_encoder_for_simple!('\u{00a0}', "\"\u{00a0}\"");
+        check_encoder_for_simple!('\u{a0}', "\"\u{a0}\"");
         check_encoder_for_simple!('\u{abcd}', "\"\u{abcd}\"");
         check_encoder_for_simple!('\u{10ffff}', "\"\u{10ffff}\"");
     }
@@ -2839,7 +2839,7 @@ mod tests {
         assert_eq!(v, i64::MAX);
 
         let res: DecodeResult<i64> = super::decode("765.25252");
-        assert_eq!(res, Err(ExpectedError("Integer".into_string(), "765.25252".into_string())));
+        assert_eq!(res, Err(ExpectedError("Integer".to_string(), "765.25252".to_string())));
     }
 
     #[test]
@@ -2847,16 +2847,16 @@ mod tests {
         assert_eq!(from_str("\""),    Err(SyntaxError(EOFWhileParsingString, 1, 2)));
         assert_eq!(from_str("\"lol"), Err(SyntaxError(EOFWhileParsingString, 1, 5)));
 
-        assert_eq!(from_str("\"\""), Ok(String("".into_string())));
-        assert_eq!(from_str("\"foo\""), Ok(String("foo".into_string())));
-        assert_eq!(from_str("\"\\\"\""), Ok(String("\"".into_string())));
-        assert_eq!(from_str("\"\\b\""), Ok(String("\x08".into_string())));
-        assert_eq!(from_str("\"\\n\""), Ok(String("\n".into_string())));
-        assert_eq!(from_str("\"\\r\""), Ok(String("\r".into_string())));
-        assert_eq!(from_str("\"\\t\""), Ok(String("\t".into_string())));
-        assert_eq!(from_str(" \"foo\" "), Ok(String("foo".into_string())));
-        assert_eq!(from_str("\"\\u12ab\""), Ok(String("\u{12ab}".into_string())));
-        assert_eq!(from_str("\"\\uAB12\""), Ok(String("\u{AB12}".into_string())));
+        assert_eq!(from_str("\"\""), Ok(String("".to_string())));
+        assert_eq!(from_str("\"foo\""), Ok(String("foo".to_string())));
+        assert_eq!(from_str("\"\\\"\""), Ok(String("\"".to_string())));
+        assert_eq!(from_str("\"\\b\""), Ok(String("\x08".to_string())));
+        assert_eq!(from_str("\"\\n\""), Ok(String("\n".to_string())));
+        assert_eq!(from_str("\"\\r\""), Ok(String("\r".to_string())));
+        assert_eq!(from_str("\"\\t\""), Ok(String("\t".to_string())));
+        assert_eq!(from_str(" \"foo\" "), Ok(String("foo".to_string())));
+        assert_eq!(from_str("\"\\u12ab\""), Ok(String("\u{12ab}".to_string())));
+        assert_eq!(from_str("\"\\uAB12\""), Ok(String("\u{AB12}".to_string())));
     }
 
     #[test]
@@ -2922,7 +2922,7 @@ mod tests {
         assert_eq!(t, (1u, 2, 3));
 
         let t: (uint, string::String) = super::decode("[1, \"two\"]").unwrap();
-        assert_eq!(t, (1u, "two".into_string()));
+        assert_eq!(t, (1u, "two".to_string()));
     }
 
     #[test]
@@ -2952,22 +2952,22 @@ mod tests {
 
         assert_eq!(from_str("{}").unwrap(), mk_object(&[]));
         assert_eq!(from_str("{\"a\": 3}").unwrap(),
-                  mk_object(&[("a".into_string(), U64(3))]));
+                  mk_object(&[("a".to_string(), U64(3))]));
 
         assert_eq!(from_str(
                       "{ \"a\": null, \"b\" : true }").unwrap(),
                   mk_object(&[
-                      ("a".into_string(), Null),
-                      ("b".into_string(), Boolean(true))]));
+                      ("a".to_string(), Null),
+                      ("b".to_string(), Boolean(true))]));
         assert_eq!(from_str("\n{ \"a\": null, \"b\" : true }\n").unwrap(),
                   mk_object(&[
-                      ("a".into_string(), Null),
-                      ("b".into_string(), Boolean(true))]));
+                      ("a".to_string(), Null),
+                      ("b".to_string(), Boolean(true))]));
         assert_eq!(from_str(
                       "{\"a\" : 1.0 ,\"b\": [ true ]}").unwrap(),
                   mk_object(&[
-                      ("a".into_string(), F64(1.0)),
-                      ("b".into_string(), Array(vec![Boolean(true)]))
+                      ("a".to_string(), F64(1.0)),
+                      ("b".to_string(), Array(vec![Boolean(true)]))
                   ]));
         assert_eq!(from_str(
                       "{\
@@ -2979,12 +2979,12 @@ mod tests {
                           ]\
                       }").unwrap(),
                   mk_object(&[
-                      ("a".into_string(), F64(1.0)),
-                      ("b".into_string(), Array(vec![
+                      ("a".to_string(), F64(1.0)),
+                      ("b".to_string(), Array(vec![
                           Boolean(true),
-                          String("foo\nbar".into_string()),
+                          String("foo\nbar".to_string()),
                           mk_object(&[
-                              ("c".into_string(), mk_object(&[("d".into_string(), Null)]))
+                              ("c".to_string(), mk_object(&[("d".to_string(), Null)]))
                           ])
                       ]))
                   ]));
@@ -3003,7 +3003,7 @@ mod tests {
             v,
             Outer {
                 inner: vec![
-                    Inner { a: (), b: 2, c: vec!["abc".into_string(), "xyz".into_string()] }
+                    Inner { a: (), b: 2, c: vec!["abc".to_string(), "xyz".to_string()] }
                 ]
             }
         );
@@ -3029,7 +3029,7 @@ mod tests {
         assert_eq!(value, None);
 
         let value: Option<string::String> = super::decode("\"jodhpurs\"").unwrap();
-        assert_eq!(value, Some("jodhpurs".into_string()));
+        assert_eq!(value, Some("jodhpurs".to_string()));
     }
 
     #[test]
@@ -3039,7 +3039,7 @@ mod tests {
 
         let s = "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}";
         let value: Animal = super::decode(s).unwrap();
-        assert_eq!(value, Frog("Henry".into_string(), 349));
+        assert_eq!(value, Frog("Henry".to_string(), 349));
     }
 
     #[test]
@@ -3048,8 +3048,8 @@ mod tests {
                   \"fields\":[\"Henry\", 349]}}";
         let mut map: BTreeMap<string::String, Animal> = super::decode(s).unwrap();
 
-        assert_eq!(map.remove(&"a".into_string()), Some(Dog));
-        assert_eq!(map.remove(&"b".into_string()), Some(Frog("Henry".into_string(), 349)));
+        assert_eq!(map.remove(&"a".to_string()), Some(Dog));
+        assert_eq!(map.remove(&"b".to_string()), Some(Frog("Henry".to_string(), 349)));
     }
 
     #[test]
@@ -3089,30 +3089,30 @@ mod tests {
     }
     #[test]
     fn test_decode_errors_struct() {
-        check_err::<DecodeStruct>("[]", ExpectedError("Object".into_string(), "[]".into_string()));
+        check_err::<DecodeStruct>("[]", ExpectedError("Object".to_string(), "[]".to_string()));
         check_err::<DecodeStruct>("{\"x\": true, \"y\": true, \"z\": \"\", \"w\": []}",
-                                  ExpectedError("Number".into_string(), "true".into_string()));
+                                  ExpectedError("Number".to_string(), "true".to_string()));
         check_err::<DecodeStruct>("{\"x\": 1, \"y\": [], \"z\": \"\", \"w\": []}",
-                                  ExpectedError("Boolean".into_string(), "[]".into_string()));
+                                  ExpectedError("Boolean".to_string(), "[]".to_string()));
         check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": {}, \"w\": []}",
-                                  ExpectedError("String".into_string(), "{}".into_string()));
+                                  ExpectedError("String".to_string(), "{}".to_string()));
         check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": \"\", \"w\": null}",
-                                  ExpectedError("Array".into_string(), "null".into_string()));
+                                  ExpectedError("Array".to_string(), "null".to_string()));
         check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": \"\"}",
-                                  MissingFieldError("w".into_string()));
+                                  MissingFieldError("w".to_string()));
     }
     #[test]
     fn test_decode_errors_enum() {
         check_err::<DecodeEnum>("{}",
-                                MissingFieldError("variant".into_string()));
+                                MissingFieldError("variant".to_string()));
         check_err::<DecodeEnum>("{\"variant\": 1}",
-                                ExpectedError("String".into_string(), "1".into_string()));
+                                ExpectedError("String".to_string(), "1".to_string()));
         check_err::<DecodeEnum>("{\"variant\": \"A\"}",
-                                MissingFieldError("fields".into_string()));
+                                MissingFieldError("fields".to_string()));
         check_err::<DecodeEnum>("{\"variant\": \"A\", \"fields\": null}",
-                                ExpectedError("Array".into_string(), "null".into_string()));
+                                ExpectedError("Array".to_string(), "null".to_string()));
         check_err::<DecodeEnum>("{\"variant\": \"C\", \"fields\": []}",
-                                UnknownVariantError("C".into_string()));
+                                UnknownVariantError("C".to_string()));
     }
 
     #[test]
@@ -3325,15 +3325,15 @@ mod tests {
 
         let mut tree = BTreeMap::new();
 
-        tree.insert("hello".into_string(), String("guten tag".into_string()));
-        tree.insert("goodbye".into_string(), String("sayonara".into_string()));
+        tree.insert("hello".to_string(), String("guten tag".to_string()));
+        tree.insert("goodbye".to_string(), String("sayonara".to_string()));
 
         let json = Array(
             // The following layout below should look a lot like
             // the pretty-printed JSON (indent * x)
             vec!
             ( // 0x
-                String("greetings".into_string()), // 1x
+                String("greetings".to_string()), // 1x
                 Object(tree), // 1x + 2x + 2x + 1x
             ) // 0x
             // End JSON array (7 lines)
@@ -3397,7 +3397,7 @@ mod tests {
         };
         let mut decoder = Decoder::new(json_obj);
         let result: Result<HashMap<uint, bool>, DecoderError> = Decodable::decode(&mut decoder);
-        assert_eq!(result, Err(ExpectedError("Number".into_string(), "a".into_string())));
+        assert_eq!(result, Err(ExpectedError("Number".to_string(), "a".to_string())));
     }
 
     fn assert_stream_equal(src: &str,
@@ -3424,7 +3424,7 @@ mod tests {
             r#"{ "foo":"bar", "array" : [0, 1, 2, 3, 4, 5], "idents":[null,true,false]}"#,
             vec![
                 (ObjectStart,             vec![]),
-                  (StringValue("bar".into_string()),   vec![Key("foo")]),
+                  (StringValue("bar".to_string()),   vec![Key("foo")]),
                   (ArrayStart,            vec![Key("array")]),
                     (U64Value(0),         vec![Key("array"), Index(0)]),
                     (U64Value(1),         vec![Key("array"), Index(1)]),
@@ -3515,7 +3515,7 @@ mod tests {
                   (F64Value(1.0),               vec![Key("a")]),
                   (ArrayStart,                  vec![Key("b")]),
                     (BooleanValue(true),        vec![Key("b"), Index(0)]),
-                    (StringValue("foo\nbar".into_string()),  vec![Key("b"), Index(1)]),
+                    (StringValue("foo\nbar".to_string()),  vec![Key("b"), Index(1)]),
                     (ObjectStart,               vec![Key("b"), Index(2)]),
                       (ObjectStart,             vec![Key("b"), Index(2), Key("c")]),
                         (NullValue,             vec![Key("b"), Index(2), Key("c"), Key("d")]),
@@ -3648,7 +3648,7 @@ mod tests {
         assert!(stack.last_is_index());
         assert!(stack.get(0) == Index(1));
 
-        stack.push_key("foo".into_string());
+        stack.push_key("foo".to_string());
 
         assert!(stack.len() == 2);
         assert!(stack.is_equal_to(&[Index(1), Key("foo")]));
@@ -3660,7 +3660,7 @@ mod tests {
         assert!(stack.get(0) == Index(1));
         assert!(stack.get(1) == Key("foo"));
 
-        stack.push_key("bar".into_string());
+        stack.push_key("bar".to_string());
 
         assert!(stack.len() == 3);
         assert!(stack.is_equal_to(&[Index(1), Key("foo"), Key("bar")]));
@@ -3721,8 +3721,8 @@ mod tests {
         assert_eq!(f64::NAN.to_json(), Null);
         assert_eq!(true.to_json(), Boolean(true));
         assert_eq!(false.to_json(), Boolean(false));
-        assert_eq!("abc".to_json(), String("abc".into_string()));
-        assert_eq!("abc".into_string().to_json(), String("abc".into_string()));
+        assert_eq!("abc".to_json(), String("abc".to_string()));
+        assert_eq!("abc".to_string().to_json(), String("abc".to_string()));
         assert_eq!((1u, 2u).to_json(), array2);
         assert_eq!((1u, 2u, 3u).to_json(), array3);
         assert_eq!([1u, 2].to_json(), array2);
@@ -3734,8 +3734,8 @@ mod tests {
         tree_map.insert("b".into_string(), 2);
         assert_eq!(tree_map.to_json(), object);
         let mut hash_map = HashMap::new();
-        hash_map.insert("a".into_string(), 1u);
-        hash_map.insert("b".into_string(), 2);
+        hash_map.insert("a".to_string(), 1u);
+        hash_map.insert("b".to_string(), 2);
         assert_eq!(hash_map.to_json(), object);
         assert_eq!(Some(15i).to_json(), I64(15));
         assert_eq!(Some(15u).to_json(), U64(15));
@@ -3778,7 +3778,7 @@ mod tests {
     }
 
     fn big_json() -> string::String {
-        let mut src = "[\n".into_string();
+        let mut src = "[\n".to_string();
         for _ in range(0i, 500) {
             src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \
                             [1,2,3]},"#);
diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs
index e700d102fef..fdbc5051f72 100644
--- a/src/libserialize/lib.rs
+++ b/src/libserialize/lib.rs
@@ -32,6 +32,7 @@ extern crate test;
 
 #[phase(plugin, link)]
 extern crate log;
+extern crate unicode;
 
 extern crate collections;
 
diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs
index 00c5158309e..558f9e603e1 100644
--- a/src/libserialize/serialize.rs
+++ b/src/libserialize/serialize.rs
@@ -308,13 +308,13 @@ impl<E, S:Encoder<E>> Encodable<S, E> for str {
 
 impl<E, S:Encoder<E>> Encodable<S, E> for String {
     fn encode(&self, s: &mut S) -> Result<(), E> {
-        s.emit_str(self.as_slice())
+        s.emit_str(self[])
     }
 }
 
 impl<E, D:Decoder<E>> Decodable<D, E> for String {
     fn decode(d: &mut D) -> Result<String, E> {
-        Ok(String::from_str(try!(d.read_str()).as_slice()))
+        d.read_str()
     }
 }