pub fn from_value<'a, T>(value: &'a Value) -> Result<T, Error>where
T: Deserialize<'a>,
Expand description
Deserialize an instance of type T
from a Firestore Value.
§Examples
#[derive(Debug, PartialEq, serde::Deserialize)]
struct T {
b: bool,
n: i64,
}
assert_eq!(
from_value::<'_, T>(&Value {
value_type: Some(ValueType::MapValue(MapValue {
fields: std::collections::HashMap::from([
(
"b".to_string(),
Value {
value_type: Some(ValueType::BooleanValue(true))
}
),
(
"n".to_string(),
Value {
value_type: Some(ValueType::IntegerValue(1))
}
)
])
}))
})?,
T { b: true, n: 1 }
);
§Deserialize GeoPoint, Reference, and Timestamp
See: with
.
§Mapping table (no type hint)
Firestore Value | serde data model |
---|---|
nullValue | unit |
booleanValue | bool |
integerValue | i64 |
doubleValue | f64 |
timestampValue | map ({ "seconds": i64, "nanos": i64 } ) |
stringValue | string |
bytesValue | bytes |
referenceValue | string |
geoPointValue | map ({ "latitude": f64, "longitude": f64 } ) |
arrayValue | seq |
mapValue | map |