1 // Copyright (c) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 //! ylong_json is a library for parsing and serializing JSON in Rust. 15 //! This library provides a convenient macro-based API for creating 16 //! JSON values, and utilities for reading and writing JSON data 17 //! from various sources. 18 19 // TODO: 1) Isolates ylong_json no_std. 20 // TODO: 2) Handles illegal Utf-8 bytes. 21 // TODO: 3) Refactors ylong_json. 22 // TODO: 4) JsonValue provides 'Contains' methods。 23 24 /// Creates an array with at least one but any number of elements. 25 #[macro_export] 26 macro_rules! array { 27 () => ({ 28 Array::new() 29 }); 30 ($($x:expr),+ $(,)?) => ({ 31 let mut array = Array::new(); 32 $( 33 array.push($x.into()); 34 )* 35 array 36 }); 37 } 38 39 /// Creates an object with at least one but any number of key-value pairs. 40 #[macro_export] 41 macro_rules! object { 42 () => ({ 43 Object::new() 44 }); 45 ($($k: expr => $v: expr);+ $(;)?) => ({ 46 let mut object = Object::new(); 47 $( 48 object.insert(String::from($k), $v.into()); 49 )* 50 object 51 }); 52 } 53 54 mod consts; 55 mod encoder; 56 mod error; 57 mod reader; 58 #[macro_use] 59 mod states; 60 mod value; 61 62 pub use error::{Error, ParseError}; 63 pub use value::{Array, Index, JsonValue, Number, Object}; 64 65 pub(crate) use encoder::{CompactEncoder, FormattedEncoder}; 66 pub(crate) use states::start_parsing; 67 68 #[cfg(feature = "c_adapter")] 69 mod adapter; 70 #[cfg(feature = "c_adapter")] 71 pub use adapter::*; 72 73 mod deserializer; 74 #[cfg(any(feature = "list_array", feature = "list_object"))] 75 mod linked_list; 76 mod serializer_compact; 77 78 #[cfg(any(feature = "list_array", feature = "list_object"))] 79 pub(crate) use linked_list::{Cursor, CursorMut, LinkedList}; 80 #[cfg(any(feature = "list_array", feature = "list_object"))] 81 pub use linked_list::{Iter, IterMut, Node}; 82 83 pub use deserializer::{from_reader, from_slice, from_str}; 84 pub use serializer_compact::{to_string, to_writer}; 85