-
Notifications
You must be signed in to change notification settings - Fork 0
/
with.rs
87 lines (86 loc) · 2.62 KB
/
with.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
76
77
78
79
80
81
82
83
84
85
86
87
//! Modules specified in `#[serde(with = "...")]` to support special values
//! such as GeoPoint, Reference, and Timestamp.
//!
//! # Serialize and Deserialize GeoPoint, Reference, and Timestamp
//!
//! ```rust
//! # fn main() -> anyhow::Result<()> {
//! use google_api_proto::google::{
//! firestore::v1::{value::ValueType, MapValue, Value},
//! r#type::LatLng,
//! };
//! use prost_types::Timestamp;
//! use serde_firestore_value::{
//! from_value, to_value,
//! with::{lat_lng, string_as_reference, timestamp},
//! };
//! use std::collections::BTreeMap;
//!
//! #[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
//! struct T {
//! #[serde(with = "lat_lng")]
//! lat_lng: LatLng,
//! #[serde(with = "string_as_reference")]
//! reference: String,
//! #[serde(with = "timestamp")]
//! timestamp: Timestamp,
//! }
//! let t = T {
//! lat_lng: LatLng {
//! latitude: 1_f64,
//! longitude: 2_f64,
//! },
//! reference: "projects/p/databases/d/documents/c".to_string(),
//! timestamp: Timestamp {
//! seconds: 3_i64,
//! nanos: 4_i32,
//! },
//! };
//! let v = Value {
//! value_type: Some(ValueType::MapValue(MapValue {
//! fields: BTreeMap::from([
//! (
//! "lat_lng".to_string(),
//! Value {
//! value_type: Some(ValueType::GeoPointValue(LatLng { latitude: 1_f64, longitude: 2_f64 })),
//! },
//! ),
//! (
//! "reference".to_string(),
//! Value {
//! value_type: Some(ValueType::ReferenceValue(
//! "projects/p/databases/d/documents/c".to_string(),
//! )),
//! },
//! ),
//! (
//! "timestamp".to_string(),
//! Value {
//! value_type: Some(ValueType::TimestampValue(Timestamp { seconds: 3_i64, nanos: 4_i32 })),
//! },
//! ),
//! ]),
//! })),
//! };
//!
//! let s = to_value(&t)?;
//! let d = from_value::<'_, T>(&s)?;
//! assert_eq!(s, v);
//! assert_eq!(d, t);
//! # Ok(())
//! # }
//! ```
#[cfg(feature = "chrono")]
pub mod chrono_date_time_as_timestamp;
pub mod lat_lng;
#[cfg(feature = "chrono")]
pub mod option_chrono_date_time_as_timestamp;
pub mod option_lat_lng;
pub mod option_string_as_reference;
#[cfg(feature = "time")]
pub mod option_time_offset_date_time_as_timestamp;
pub mod option_timestamp;
pub mod string_as_reference;
#[cfg(feature = "time")]
pub mod time_offset_date_time_as_timestamp;
pub mod timestamp;