pub fn deserialize<'de, D>(deserializer: D) -> Result<String, D::Error>where
D: Deserializer<'de>,
Expand description
Deserialize String
from referenceValue
.
ยงExamples
use serde_firestore_value::google::firestore::v1::{value::ValueType, MapValue, Value};
use serde_firestore_value::{from_value, with::string_as_reference};
#[derive(Debug, Eq, PartialEq, serde::Deserialize)]
struct S {
#[serde(deserialize_with = "string_as_reference::deserialize")]
r: String,
s: String,
}
let o = S {
r: "projects/p/databases/d/documents/c/1".to_string(),
s: "s1".to_string(),
};
let v = Value {
value_type: Some(ValueType::MapValue(MapValue {
fields: {
let mut fields = std::collections::HashMap::new();
fields.insert(
"r".to_string(),
Value {
value_type: Some(ValueType::ReferenceValue(
"projects/p/databases/d/documents/c/1".to_string(),
)),
},
);
fields.insert(
"s".to_string(),
Value {
value_type: Some(ValueType::StringValue("s1".to_string())),
},
);
fields
},
})),
};
let d = from_value::<'_, S>(&v)?;
assert_eq!(d, o);