@@ -309,7 +309,7 @@ impl<'a> Encoder<'a> {
309309 }
310310
311311 /// Encode the specified struct into a json [u8]
312- pub fn buffer_encode < T : Encodable < Encoder < ' a > , io:: IoError > > ( to_encode_object : & T ) -> ~ [ u8 ] {
312+ pub fn buffer_encode < T : Encodable < Encoder < ' a > , io:: IoError > > ( to_encode_object : & T ) -> Vec < u8 > {
313313 //Serialize the object in a string using a writer
314314 let mut m = MemWriter :: new ( ) ;
315315 {
@@ -322,8 +322,8 @@ impl<'a> Encoder<'a> {
322322
323323 /// Encode the specified struct into a json str
324324 pub fn str_encode < T : Encodable < Encoder < ' a > , io:: IoError > > ( to_encode_object : & T ) -> ~str {
325- let buff: ~ [ u8 ] = Encoder :: buffer_encode ( to_encode_object) ;
326- str:: from_utf8_owned ( buff) . unwrap ( )
325+ let buff = Encoder :: buffer_encode ( to_encode_object) ;
326+ str:: from_utf8 ( buff. as_slice ( ) ) . unwrap ( ) . to_owned ( )
327327 }
328328}
329329
@@ -484,7 +484,7 @@ impl<'a> ::Encoder<io::IoError> for Encoder<'a> {
484484 let mut check_encoder = Encoder :: new ( & mut buf) ;
485485 try!( f ( & mut check_encoder) ) ;
486486 let buf = buf. unwrap ( ) ;
487- let out = from_utf8 ( buf) . unwrap ( ) ;
487+ let out = from_utf8 ( buf. as_slice ( ) ) . unwrap ( ) ;
488488 let needs_wrapping = out. char_at ( 0 ) != '"' &&
489489 out. char_at_reverse ( out. len ( ) ) != '"' ;
490490 if needs_wrapping { try!( write ! ( self . wr, "\" " ) ) ; }
@@ -715,7 +715,7 @@ impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> {
715715 let mut check_encoder = PrettyEncoder :: new( & mut buf) ;
716716 try!( f( & mut check_encoder) ) ;
717717 let buf = buf. unwrap( ) ;
718- let out = from_utf8( buf) . unwrap( ) ;
718+ let out = from_utf8( buf. as_slice ( ) ) . unwrap( ) ;
719719 let needs_wrapping = out. char_at( 0 ) != '"' &&
720720 out. char_at_reverse( out. len( ) ) != '"' ;
721721 if needs_wrapping { try!( write ! ( self . wr, "\" " ) ) ; }
@@ -763,7 +763,7 @@ impl Json {
763763 pub fn to_pretty_str ( & self ) -> ~str {
764764 let mut s = MemWriter :: new ( ) ;
765765 self . to_pretty_writer ( & mut s as & mut io:: Writer ) . unwrap ( ) ;
766- str:: from_utf8_owned ( s. unwrap ( ) ) . unwrap ( )
766+ str:: from_utf8 ( s. unwrap ( ) . as_slice ( ) ) . unwrap ( ) . to_owned ( )
767767 }
768768
769769 /// If the Json value is an Object, returns the value associated with the provided key.
@@ -1927,7 +1927,7 @@ mod tests {
19271927
19281928 let mut m = MemWriter::new();
19291929 f(&mut m as &mut io::Writer);
1930- str::from_utf8_owned (m.unwrap()) .unwrap()
1930+ str::from_utf8 (m.unwrap().as_slice()) .unwrap().to_owned ()
19311931 }
19321932
19331933 #[test]
@@ -2528,7 +2528,7 @@ mod tests {
25282528 hm. encode( & mut encoder) . unwrap( ) ;
25292529 }
25302530 let bytes = mem_buf. unwrap( ) ;
2531- let json_str = from_utf8( bytes) . unwrap( ) ;
2531+ let json_str = from_utf8( bytes. as_slice ( ) ) . unwrap( ) ;
25322532 match from_str( json_str) {
25332533 Err ( _) => fail!( "Unable to parse json_str: {:?}" , json_str) ,
25342534 _ => { } // it parsed and we are good to go
@@ -2548,7 +2548,7 @@ mod tests {
25482548 hm. encode( & mut encoder) . unwrap( ) ;
25492549 }
25502550 let bytes = mem_buf. unwrap( ) ;
2551- let json_str = from_utf8( bytes) . unwrap( ) ;
2551+ let json_str = from_utf8( bytes. as_slice ( ) ) . unwrap( ) ;
25522552 match from_str( json_str) {
25532553 Err ( _) => fail!( "Unable to parse json_str: {:?}" , json_str) ,
25542554 _ => { } // it parsed and we are good to go
0 commit comments