pub fn to_value<T>(value: &T) -> Result<Value, Error>where
T: Serialize,
Expand description
Serialize an instance of type T
to a Firestore Value.
§Examples
#[derive(serde::Serialize)]
struct T {
b: bool,
n: i64,
}
assert_eq!(
to_value(&T { b: true, n: 1 })?,
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))
}
)
])
}))
}
);
§Serialize GeoPoint, Reference, and Timestamp
See: with
.
§Mapping table
serde data model | Firestore Value |
---|---|
bool | booleanValue |
i8 | integerValue |
i16 | integerValue |
i32 | integerValue |
i64 | integerValue |
i128 | (not supported) |
u8 | integerValue |
u16 | integerValue |
u32 | integerValue |
u64 | (not supported) |
u128 | (not supported) |
f32 | doubleValue |
f64 | doubleValue |
char | stringValue |
string | stringValue |
byte array | bytesValue |
option | nullValue or (value) |
unit | nullValue |
unit_struct | nullValue |
unit_variant | stringValue |
newtype_struct | (value) |
newtype_struct (reference) | referenceValue |
newtype_variant | mapValue ({ (name): (value) } ) |
seq | arrayValue |
tuple | arrayValue |
tuple_struct | arrayValue |
tuple_variant | mapValue ({ (name): arrayValue } ) |
map | mapValue ({ (key): (value) } ) |
struct | mapValue ({ (field): (value) } ) |
struct (lat_lng) | geoPointValue |
struct (timestamp) | timestampValue |
struct_variant | mapValue ({ (name): mapValue } ) |