7878//! data_vector: Vec<u8>,
7979//! }
8080//!
81- //! fn main() {
82- //! let object = TestStruct {
83- //! data_int: 1,
84- //! data_str: "homura".to_string(),
85- //! data_vector: vec![2,3,4,5],
86- //! };
81+ //! let object = TestStruct {
82+ //! data_int: 1,
83+ //! data_str: "homura".to_string(),
84+ //! data_vector: vec![2,3,4,5],
85+ //! };
8786//!
88- //! // Serialize using `json::encode`
89- //! let encoded = json::encode(&object).unwrap();
87+ //! // Serialize using `json::encode`
88+ //! let encoded = json::encode(&object).unwrap();
9089//!
91- //! // Deserialize using `json::decode`
92- //! let decoded: TestStruct = json::decode(&encoded[..]).unwrap();
93- //! }
90+ //! // Deserialize using `json::decode`
91+ //! let decoded: TestStruct = json::decode(&encoded[..]).unwrap();
9492//! ```
9593//!
9694//! ## Using the `ToJson` trait
125123//! val: Json,
126124//! }
127125//!
128- //! fn main() {
129- //! let num = ComplexNum { a: 0.0001, b: 12.539 };
130- //! let data: String = json::encode(&ComplexNumRecord{
131- //! uid: 1,
132- //! dsc: "test".to_string(),
133- //! val: num.to_json(),
134- //! }).unwrap();
135- //! println!("data: {}", data);
136- //! // data: {"uid":1,"dsc":"test","val":"0.0001+12.539i"};
137- //! }
126+ //! let num = ComplexNum { a: 0.0001, b: 12.539 };
127+ //! let data: String = json::encode(&ComplexNumRecord{
128+ //! uid: 1,
129+ //! dsc: "test".to_string(),
130+ //! val: num.to_json(),
131+ //! }).unwrap();
132+ //! println!("data: {}", data);
133+ //! // data: {"uid":1,"dsc":"test","val":"0.0001+12.539i"};
138134//! ```
139135//!
140136//! ### Verbose example of `ToJson` usage
164160//! }
165161//! }
166162//!
167- //! fn main() {
168- //! // Serialize using `ToJson`
169- //! let input_data = TestStruct {
170- //! data_int: 1,
171- //! data_str: "madoka".to_string(),
172- //! data_vector: vec![2,3,4,5],
173- //! };
174- //! let json_obj: Json = input_data.to_json();
175- //! let json_str: String = json_obj.to_string();
163+ //! // Serialize using `ToJson`
164+ //! let input_data = TestStruct {
165+ //! data_int: 1,
166+ //! data_str: "madoka".to_string(),
167+ //! data_vector: vec![2,3,4,5],
168+ //! };
169+ //! let json_obj: Json = input_data.to_json();
170+ //! let json_str: String = json_obj.to_string();
176171//!
177- //! // Deserialize like before
178- //! let decoded: TestStruct = json::decode(&json_str).unwrap();
179- //! }
172+ //! // Deserialize like before
173+ //! let decoded: TestStruct = json::decode(&json_str).unwrap();
180174//! ```
181175
182176use self :: DecoderError :: * ;
@@ -1269,34 +1263,22 @@ impl Json {
12691263
12701264 /// Returns `true` if the Json value is a `Number`.
12711265 pub fn is_number ( & self ) -> bool {
1272- match * self {
1273- Json :: I64 ( _) | Json :: U64 ( _) | Json :: F64 ( _) => true ,
1274- _ => false ,
1275- }
1266+ matches ! ( * self , Json :: I64 ( _) | Json :: U64 ( _) | Json :: F64 ( _) )
12761267 }
12771268
12781269 /// Returns `true` if the Json value is a `i64`.
12791270 pub fn is_i64 ( & self ) -> bool {
1280- match * self {
1281- Json :: I64 ( _) => true ,
1282- _ => false ,
1283- }
1271+ matches ! ( * self , Json :: I64 ( _) )
12841272 }
12851273
12861274 /// Returns `true` if the Json value is a `u64`.
12871275 pub fn is_u64 ( & self ) -> bool {
1288- match * self {
1289- Json :: U64 ( _) => true ,
1290- _ => false ,
1291- }
1276+ matches ! ( * self , Json :: U64 ( _) )
12921277 }
12931278
12941279 /// Returns `true` if the Json value is a `f64`.
12951280 pub fn is_f64 ( & self ) -> bool {
1296- match * self {
1297- Json :: F64 ( _) => true ,
1298- _ => false ,
1299- }
1281+ matches ! ( * self , Json :: F64 ( _) )
13001282 }
13011283
13021284 /// If the Json value is a number, returns or cast it to a `i64`;
@@ -1416,6 +1398,7 @@ enum ParserState {
14161398/// structure of the JSON stream.
14171399///
14181400/// An example is `foo.bar[3].x`.
1401+ #[ derive( Default ) ]
14191402pub struct Stack {
14201403 stack : Vec < InternalStackElement > ,
14211404 str_buffer : Vec < u8 > ,
@@ -1442,7 +1425,7 @@ enum InternalStackElement {
14421425
14431426impl Stack {
14441427 pub fn new ( ) -> Stack {
1445- Stack { stack : Vec :: new ( ) , str_buffer : Vec :: new ( ) }
1428+ Self :: default ( )
14461429 }
14471430
14481431 /// Returns The number of elements in the Stack.
@@ -1547,10 +1530,7 @@ impl Stack {
15471530
15481531 // Used by Parser to test whether the top-most element is an index.
15491532 fn last_is_index ( & self ) -> bool {
1550- match self . stack . last ( ) {
1551- Some ( InternalIndex ( _) ) => true ,
1552- _ => false ,
1553- }
1533+ matches ! ( self . stack. last( ) , Some ( InternalIndex ( _) ) )
15541534 }
15551535
15561536 // Used by Parser to increment the index of the top-most element.
0 commit comments