serde_firestore_value/with/lat_lng.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//! (De)serialize `LatLng` as `geoPointValue`.
use crate::google::r#type::LatLng;
/// Deserialize `LatLng` from `geoPointValue`.
///
/// # Examples
///
/// ```rust
/// # fn main() -> anyhow::Result<()> {
/// use serde_firestore_value::google::{
/// firestore::v1::{value::ValueType, Value},
/// r#type::LatLng,
/// };
/// use serde_firestore_value::{from_value, with::lat_lng};
///
/// #[derive(Debug, PartialEq, serde::Deserialize)]
/// struct S(#[serde(deserialize_with = "lat_lng::deserialize")] LatLng);
/// let o = S(LatLng {
/// latitude: 1_f64,
/// longitude: 2_f64,
/// });
/// let v = Value {
/// value_type: Some(ValueType::GeoPointValue(LatLng {
/// latitude: 1_f64,
/// longitude: 2_f64,
/// })),
/// };
/// let d = from_value::<'_, S>(&v)?;
/// assert_eq!(d, o);
/// # Ok(())
/// # }
/// ```
pub fn deserialize<'de, D>(deserializer: D) -> Result<LatLng, D::Error>
where
D: serde::Deserializer<'de>,
{
crate::de::with::lat_lng_as_geo_point::deserialize_lat_lng(deserializer)
}
/// Serialize `LatLng` as `geoPointValue`.
///
/// # Examples
///
/// ```rust
/// # fn main() -> anyhow::Result<()> {
/// use serde_firestore_value::google::{
/// firestore::v1::{value::ValueType, Value},
/// r#type::LatLng,
/// };
/// use serde_firestore_value::{to_value, with::lat_lng};
///
/// #[derive(Debug, PartialEq, serde::Serialize)]
/// struct S(#[serde(serialize_with = "lat_lng::serialize")] LatLng);
/// let o = S(LatLng {
/// latitude: 1_f64,
/// longitude: 2_f64,
/// });
/// let v = Value {
/// value_type: Some(ValueType::GeoPointValue(LatLng {
/// latitude: 1_f64,
/// longitude: 2_f64,
/// })),
/// };
/// let s = to_value(&o)?;
/// assert_eq!(s, v);
/// # Ok(())
/// # }
/// ```
pub fn serialize<S>(lat_lng: &LatLng, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
crate::ser::with::lat_lng_as_geo_point::serialize_lat_lng(lat_lng, serializer)
}