serde_firestore_value/
with.rs

1//! Modules specified in `#[serde(with = "...")]` to support special values
2//! such as GeoPoint, Reference, and Timestamp.
3//!
4//! # Serialize and Deserialize GeoPoint, Reference, and Timestamp
5//!
6//! ```rust
7//! # fn main() -> anyhow::Result<()> {
8//! use serde_firestore_value::google::{
9//!     firestore::v1::{value::ValueType, MapValue, Value},
10//!     r#type::LatLng,
11//! };
12//! use serde_firestore_value::{
13//!     from_value, to_value,
14//!     with::{lat_lng, string_as_reference, timestamp},
15//! };
16//!
17//! #[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
18//! struct T {
19//!     #[serde(with = "lat_lng")]
20//!     lat_lng: LatLng,
21//!     #[serde(with = "string_as_reference")]
22//!     reference: String,
23//!     #[serde(with = "timestamp")]
24//!     timestamp: prost_types::Timestamp,
25//! }
26//! let t = T {
27//!     lat_lng: LatLng {
28//!         latitude: 1_f64,
29//!         longitude: 2_f64,
30//!     },
31//!     reference: "projects/p/databases/d/documents/c".to_string(),
32//!     timestamp: prost_types::Timestamp {
33//!         seconds: 3_i64,
34//!         nanos: 4_i32,
35//!     },
36//! };
37//! let v = Value {
38//!     value_type: Some(ValueType::MapValue(MapValue {
39//!         fields: std::collections::HashMap::from([
40//!             (
41//!                 "lat_lng".to_string(),
42//!                 Value {
43//!                     value_type: Some(ValueType::GeoPointValue(LatLng { latitude: 1_f64, longitude: 2_f64 })),
44//!                 },
45//!             ),
46//!             (
47//!                 "reference".to_string(),
48//!                 Value {
49//!                     value_type: Some(ValueType::ReferenceValue(
50//!                         "projects/p/databases/d/documents/c".to_string(),
51//!                     )),
52//!                 },
53//!             ),
54//!             (
55//!                 "timestamp".to_string(),
56//!                 Value {
57//!                     value_type: Some(ValueType::TimestampValue(prost_types::Timestamp { seconds: 3_i64, nanos: 4_i32 })),
58//!                 },
59//!             ),
60//!         ]),
61//!     })),
62//! };
63//!
64//! let s = to_value(&t)?;
65//! let d = from_value::<'_, T>(&s)?;
66//! assert_eq!(s, v);
67//! assert_eq!(d, t);
68//! #     Ok(())
69//! # }
70//! ```
71
72#[cfg(feature = "chrono")]
73pub mod chrono_date_time_as_timestamp;
74pub mod lat_lng;
75#[cfg(feature = "chrono")]
76pub mod option_chrono_date_time_as_timestamp;
77pub mod option_lat_lng;
78pub mod option_string_as_reference;
79#[cfg(feature = "time")]
80pub mod option_time_offset_date_time_as_timestamp;
81pub mod option_timestamp;
82pub mod string_as_reference;
83#[cfg(feature = "time")]
84pub mod time_offset_date_time_as_timestamp;
85pub mod timestamp;
86pub mod vec_string_as_reference;