serde_firestore_value::with::lat_lng

Function serialize

Source
pub fn serialize<S>(lat_lng: &LatLng, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,
Expand description

Serialize LatLng as geoPointValue.

ยงExamples

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);