11//! 
22//!
3- //! # JSON in Rust
3+ //! # json-rust
44//!
5- //! Parse and serialize JSON with ease.
5+ //! Parse and serialize [ JSON](http://json.org/) with ease.
66//!
77//! **[Complete Documentation](http://terhix.com/doc/json/) - [Cargo](https://crates.io/crates/json) - [Repository](https://github.com/maciejhirsz/json-rust)**
88//!
9- //! # Why?
9+ //! ## Why?
1010//!
1111//! JSON is a very loose format where anything goes - arrays can hold mixed
1212//! types, object keys can change types between API calls or not include
139139//! data.push("foo");
140140//! data.push(false);
141141//!
142- //! assert_eq!(json::stringify( data), "[10,\ "foo\ ",false]");
142+ //! assert_eq!(data.dump( ), r# "[10,"foo",false]"# );
143143//! ```
144144//!
145145//! Putting fields on objects:
150150//! data["answer"] = 42.into();
151151//! data["foo"] = "bar".into();
152152//!
153- //! assert_eq!(json::stringify( data), "{\ "answer\ ":42,\ "foo\":\ "bar\ "}");
153+ //! assert_eq!(data.dump( ), r#"{ "answer":42,"foo": "bar"}"# );
154154//! ```
155155//!
156156//! `array!` macro:
159159//! # #[macro_use] extern crate json;
160160//! # fn main() {
161161//! let data = array!["foo", "bar", 100, true, json::Null];
162- //! assert_eq!(json::stringify( data), "[\ "foo\",\ "bar\ ",100,true,null]");
162+ //! assert_eq!(data.dump( ), r#"[ "foo", "bar",100,true,null]"# );
163163//! # }
164164//! ```
165165//!
174174//! "canJSON" => true
175175//! };
176176//! assert_eq!(
177- //! json::stringify( data),
177+ //! data.dump( ),
178178//! // Because object is internally using a BTreeMap,
179179//! // the key order is alphabetical
180- //! "{\ "age\ ":30,\ "canJSON\ ":true,\ "name\":\ "John Doe\ "}"
180+ //! r#"{ "age":30,"canJSON":true,"name": "John Doe"}"#
181181//! );
182182//! # }
183183//! ```
@@ -296,27 +296,27 @@ macro_rules! object {
296296
297297macro_rules! implement_extras {
298298 ( $from: ty) => {
299- impl Into < JsonValue > for Option <$from> {
300- fn into ( self ) -> JsonValue {
301- match self {
299+ impl From < Option <$from>> for JsonValue {
300+ fn from ( val : Option <$from> ) -> JsonValue {
301+ match val {
302302 Some ( value) => value. into( ) ,
303303 None => Null ,
304304 }
305305 }
306306 }
307307
308- impl Into < JsonValue > for Vec <$from> {
309- fn into ( mut self ) -> JsonValue {
310- JsonValue :: Array ( self . drain( ..)
308+ impl From < Vec <$from>> for JsonValue {
309+ fn from ( mut val : Vec <$from> ) -> JsonValue {
310+ JsonValue :: Array ( val . drain( ..)
311311 . map( |value| value. into( ) )
312312 . collect:: <Vec <JsonValue >>( )
313313 )
314314 }
315315 }
316316
317- impl Into < JsonValue > for Vec <Option <$from>> {
318- fn into ( mut self ) -> JsonValue {
319- JsonValue :: Array ( self . drain( ..)
317+ impl From < Vec <Option <$from>>> for JsonValue {
318+ fn from ( mut val : Vec < Option <$from>> ) -> JsonValue {
319+ JsonValue :: Array ( val . drain( ..)
320320 . map( |item| item. into( ) )
321321 . collect:: <Vec <JsonValue >>( )
322322 )
@@ -327,64 +327,64 @@ macro_rules! implement_extras {
327327
328328macro_rules! implement {
329329 ( $to: ident, $from: ty as $wanted: ty) => {
330- impl Into < JsonValue > for $from {
331- fn into ( self ) -> JsonValue {
332- JsonValue :: $to( self as $wanted)
330+ impl From <$from > for JsonValue {
331+ fn from ( val : $from ) -> JsonValue {
332+ JsonValue :: $to( val as $wanted)
333333 }
334334 }
335335
336336 implement_extras!( $from) ;
337337 } ;
338338 ( $to: ident, $from: ty) => {
339- impl Into < JsonValue > for $from {
340- fn into ( self ) -> JsonValue {
341- JsonValue :: $to( self )
339+ impl From <$from > for JsonValue {
340+ fn from ( val : $from ) -> JsonValue {
341+ JsonValue :: $to( val )
342342 }
343343 }
344344
345345 implement_extras!( $from) ;
346346 }
347347}
348348
349- impl < ' a > Into < JsonValue > for & ' a str {
350- fn into ( self ) -> JsonValue {
351- JsonValue :: String ( self . to_string ( ) )
349+ impl < ' a > From < & ' a str > for JsonValue {
350+ fn from ( val : & ' a str ) -> JsonValue {
351+ JsonValue :: String ( val . to_string ( ) )
352352 }
353353}
354354
355- impl < ' a > Into < JsonValue > for Option < & ' a str > {
356- fn into ( self ) -> JsonValue {
357- match self {
355+ impl < ' a > From < Option < & ' a str > > for JsonValue {
356+ fn from ( val : Option < & ' a str > ) -> JsonValue {
357+ match val {
358358 Some ( value) => value. into ( ) ,
359359 None => Null ,
360360 }
361361 }
362362}
363363
364- impl Into < JsonValue > for HashMap < String , JsonValue > {
365- fn into ( mut self ) -> JsonValue {
364+ impl From < HashMap < String , JsonValue > > for JsonValue {
365+ fn from ( mut val : HashMap < String , JsonValue > ) -> JsonValue {
366366 let mut object = BTreeMap :: new ( ) ;
367367
368- for ( key, value) in self . drain ( ) {
368+ for ( key, value) in val . drain ( ) {
369369 object. insert ( key, value) ;
370370 }
371371
372372 JsonValue :: Object ( object)
373373 }
374374}
375375
376- impl Into < JsonValue > for Option < HashMap < String , JsonValue > > {
377- fn into ( self ) -> JsonValue {
378- match self {
376+ impl From < Option < HashMap < String , JsonValue > > > for JsonValue {
377+ fn from ( val : Option < HashMap < String , JsonValue > > ) -> JsonValue {
378+ match val {
379379 Some ( value) => value. into ( ) ,
380380 None => Null ,
381381 }
382382 }
383383}
384384
385- impl Into < JsonValue > for Option < JsonValue > {
386- fn into ( self ) -> JsonValue {
387- match self {
385+ impl From < Option < JsonValue > > for JsonValue {
386+ fn from ( val : Option < JsonValue > ) -> JsonValue {
387+ match val {
388388 Some ( value) => value,
389389 None => Null ,
390390 }
0 commit comments