serde_firestore_value

Function from_value

Source
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 Valueserde data model
nullValueunit
booleanValuebool
integerValuei64
doubleValuef64
timestampValuemap ({ "seconds": i64, "nanos": i64 })
stringValuestring
bytesValuebytes
referenceValuestring
geoPointValuemap ({ "latitude": f64, "longitude": f64 })
arrayValueseq
mapValuemap