simd_json/serde/value/
borrowed.rs

1mod de;
2mod se;
3
4use crate::{BorrowedValue, Result};
5use serde_ext::de::Deserialize;
6use serde_ext::ser::Serialize;
7
8/// Tries to convert a struct that implements serde's serialize into
9/// an `BorrowedValue`
10///
11/// # Errors
12///
13/// Will return `Err` if value fails to be turned into a borrowed value
14pub fn to_value<'se, T>(value: T) -> Result<BorrowedValue<'se>>
15where
16    T: Serialize,
17{
18    value.serialize(se::Serializer::default())
19}
20
21/// Tries to convert a `BorrowedValue` into a struct that implements
22/// serde's Deserialize interface
23///
24/// # Errors
25///
26/// Will return `Err` if `value` can not be deserialized
27pub fn from_value<'de, T>(value: BorrowedValue<'de>) -> Result<T>
28where
29    T: Deserialize<'de>,
30{
31    T::deserialize(value)
32}
33
34/// Tries to convert a `&BorrowedValue` into a struct that implements
35/// serde's Deserialize interface
36///
37/// # Errors
38///
39/// Will return `Err` if `value` fails to be deserialized
40pub fn from_refvalue<'de, T>(value: &'de BorrowedValue<'de>) -> Result<T>
41where
42    T: Deserialize<'de>,
43{
44    T::deserialize(value)
45}