2525//! due to less allocations. By borrowing a DOM, the library ensures that no additional memory is
2626//! allocated for `Strings`, that contain no JSON escape codes.
2727//!
28+ //! # Usage
29+ //! ```rust
30+ //! use std::io;
31+ //! fn main() -> io::Result<()> {
32+ //! let data: &str = r#"{"bool": true, "key": "123"}"#;
33+ //! // Note that serde_json_borrow::Value<'ctx> is tied to the lifetime of data.
34+ //! let value: serde_json_borrow::Value = serde_json::from_str(&data)?;
35+ //! assert_eq!(value.get("bool"), &serde_json_borrow::Value::Bool(true));
36+ //! assert_eq!(value.get("key"), &serde_json_borrow::Value::Str("123".into()));
37+ //! // Using OwnedValue will take ownership of the String.
38+ //! let value: serde_json_borrow::OwnedValue = serde_json_borrow::OwnedValue::from_str(&data)?;
39+ //! assert_eq!(value.get("bool"), &serde_json_borrow::Value::Bool(true));
40+ //! assert_eq!(value.get("key"), &serde_json_borrow::Value::Str("123".into()));
41+ //! Ok(())
42+ //! }
43+ //! ```
44+ //!
2845//! ## OwnedValue
2946//! You can take advantage of [`OwnedValue`] to parse a `String` containing
3047//! unparsed `JSON` into a `Value` without having to worry about lifetimes,
3653//! support for escaped data in keys. Without the `cowkeys` feature flag `&str` is used, which does
3754//! not allow any JSON escaping characters in keys.
3855//!
39- //! List of _unsupported_ characters (https://www.json.org/json-en.html) in object keys without `cowkeys` feature flag.
56+ //! List of _unsupported_ characters (< https://www.json.org/json-en.html> ) in object keys without `cowkeys` feature flag.
4057//!
4158//! ```text
4259//! \" represents the quotation mark character (U+0022).
4865//! \r represents the carriage return character (U+000D).
4966//! \t represents the character tabulation character (U+0009).
5067//! ```
51- //! # Usage
52- //! ```rust
53- //! use std::io;
54- //! use serde_json_borrow::Value;
55- //! fn main() -> io::Result<()> {
56- //! let data = r#"{"bool": true, "key": "123"}"#;
57- //! let value: Value = serde_json::from_str(&data)?;
58- //! assert_eq!(value.get("bool"), &Value::Bool(true));
59- //! assert_eq!(value.get("key"), &Value::Str("123".into()));
60- //! Ok(())
61- //! }
62- //! ```
6368//! # Performance
6469//! Performance gain depends on how many allocations can be avoided, and how many objects there are,
6570//! as deserializing into a vec is significantly faster.
@@ -76,13 +81,13 @@ mod deserializer;
7681mod index;
7782mod num;
7883mod object_vec;
79- mod owned ;
84+ mod ownedvalue ;
8085mod ser;
8186mod value;
8287
8388#[ cfg( feature = "cowkeys" ) ]
8489mod cowstr;
8590
8691pub use object_vec:: { KeyStrType , ObjectAsVec , ObjectAsVec as Map } ;
87- pub use owned :: OwnedValue ;
92+ pub use ownedvalue :: OwnedValue ;
8893pub use value:: Value ;
0 commit comments