File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,53 @@ use error::Error;
64
64
/// }
65
65
/// ```
66
66
///
67
+ /// # Ownership
68
+ ///
69
+ /// The typical usage of `RawValue` will be in the borrowed form:
70
+ ///
71
+ /// ```
72
+ /// # #[macro_use]
73
+ /// # extern crate serde_derive;
74
+ /// # extern crate serde_json;
75
+ /// #
76
+ /// # use serde_json::value::RawValue;
77
+ /// #
78
+ /// #[derive(Deserialize)]
79
+ /// struct SomeStruct<'a> {
80
+ /// #[serde(borrow)]
81
+ /// raw_value: &'a RawValue,
82
+ /// }
83
+ /// #
84
+ /// # fn main() {}
85
+ /// ```
86
+ ///
87
+ /// The borrowed form is suitable when deserializing through
88
+ /// [`serde_json::from_str`] and [`serde_json::from_slice`] which support
89
+ /// borrowing from the input data without memory allocation.
90
+ ///
91
+ /// When deserializing through [`serde_json::from_reader`] you will need to use
92
+ /// the boxed form of `RawValue` instead. This is almost as efficient but
93
+ /// involves buffering the raw value from the I/O stream into memory.
94
+ ///
95
+ /// [`serde_json::from_str`]: ../fn.from_str.html
96
+ /// [`serde_json::from_slice`]: ../fn.from_slice.html
97
+ /// [`serde_json::from_reader`]: ../fn.from_reader.html
98
+ ///
99
+ /// ```
100
+ /// # #[macro_use]
101
+ /// # extern crate serde_derive;
102
+ /// # extern crate serde_json;
103
+ /// #
104
+ /// # use serde_json::value::RawValue;
105
+ /// #
106
+ /// #[derive(Deserialize)]
107
+ /// struct SomeStruct {
108
+ /// raw_value: Box<RawValue>,
109
+ /// }
110
+ /// #
111
+ /// # fn main() {}
112
+ /// ```
113
+ ///
67
114
/// # Note
68
115
///
69
116
/// `RawValue` is only available if serde\_json is built with the `"raw_value"`
You can’t perform that action at this time.
0 commit comments