@@ -309,7 +309,7 @@ impl<'a> Encoder<'a> {
309
309
}
310
310
311
311
/// 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 > {
313
313
//Serialize the object in a string using a writer
314
314
let mut m = MemWriter :: new ( ) ;
315
315
{
@@ -322,8 +322,8 @@ impl<'a> Encoder<'a> {
322
322
323
323
/// Encode the specified struct into a json str
324
324
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 ( )
327
327
}
328
328
}
329
329
@@ -484,7 +484,7 @@ impl<'a> ::Encoder<io::IoError> for Encoder<'a> {
484
484
let mut check_encoder = Encoder :: new ( & mut buf) ;
485
485
try!( f ( & mut check_encoder) ) ;
486
486
let buf = buf. unwrap ( ) ;
487
- let out = from_utf8 ( buf) . unwrap ( ) ;
487
+ let out = from_utf8 ( buf. as_slice ( ) ) . unwrap ( ) ;
488
488
let needs_wrapping = out. char_at ( 0 ) != '"' &&
489
489
out. char_at_reverse ( out. len ( ) ) != '"' ;
490
490
if needs_wrapping { try!( write ! ( self . wr, "\" " ) ) ; }
@@ -715,7 +715,7 @@ impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> {
715
715
let mut check_encoder = PrettyEncoder :: new( & mut buf) ;
716
716
try!( f( & mut check_encoder) ) ;
717
717
let buf = buf. unwrap( ) ;
718
- let out = from_utf8( buf) . unwrap( ) ;
718
+ let out = from_utf8( buf. as_slice ( ) ) . unwrap( ) ;
719
719
let needs_wrapping = out. char_at( 0 ) != '"' &&
720
720
out. char_at_reverse( out. len( ) ) != '"' ;
721
721
if needs_wrapping { try!( write ! ( self . wr, "\" " ) ) ; }
@@ -763,7 +763,7 @@ impl Json {
763
763
pub fn to_pretty_str ( & self ) -> ~str {
764
764
let mut s = MemWriter :: new ( ) ;
765
765
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 ( )
767
767
}
768
768
769
769
/// If the Json value is an Object, returns the value associated with the provided key.
@@ -1282,8 +1282,8 @@ pub fn from_reader(rdr: &mut io::Reader) -> DecodeResult<Json> {
1282
1282
Ok ( c) => c,
1283
1283
Err ( e) => return Err ( IoError ( e) )
1284
1284
} ;
1285
- let s = match str:: from_utf8_owned ( contents) {
1286
- Some ( s) => s,
1285
+ let s = match str:: from_utf8 ( contents. as_slice ( ) ) {
1286
+ Some ( s) => s. to_owned ( ) ,
1287
1287
None => return Err ( ParseError ( ~"contents not utf-8 ", 0 , 0 ) )
1288
1288
} ;
1289
1289
let mut parser = Parser :: new ( s. chars ( ) ) ;
@@ -1927,7 +1927,7 @@ mod tests {
1927
1927
1928
1928
let mut m = MemWriter::new();
1929
1929
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 ()
1931
1931
}
1932
1932
1933
1933
#[test]
@@ -2528,7 +2528,7 @@ mod tests {
2528
2528
hm. encode( & mut encoder) . unwrap( ) ;
2529
2529
}
2530
2530
let bytes = mem_buf. unwrap( ) ;
2531
- let json_str = from_utf8( bytes) . unwrap( ) ;
2531
+ let json_str = from_utf8( bytes. as_slice ( ) ) . unwrap( ) ;
2532
2532
match from_str( json_str) {
2533
2533
Err ( _) => fail!( "Unable to parse json_str: {:?}" , json_str) ,
2534
2534
_ => { } // it parsed and we are good to go
@@ -2548,7 +2548,7 @@ mod tests {
2548
2548
hm. encode( & mut encoder) . unwrap( ) ;
2549
2549
}
2550
2550
let bytes = mem_buf. unwrap( ) ;
2551
- let json_str = from_utf8( bytes) . unwrap( ) ;
2551
+ let json_str = from_utf8( bytes. as_slice ( ) ) . unwrap( ) ;
2552
2552
match from_str( json_str) {
2553
2553
Err ( _) => fail!( "Unable to parse json_str: {:?}" , json_str) ,
2554
2554
_ => { } // it parsed and we are good to go
0 commit comments