MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / serialize

Method serialize

cel/src/ser.rs:83–106  ·  view source on GitHub ↗
(&self, serializer: S)

Source from the content-addressed store, hash-verified

81#[cfg(feature = "chrono")]
82impl ser::Serialize for Duration {
83 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
84 where
85 S: ser::Serializer,
86 {
87 // chrono::Duration's Serialize impl isn't stable yet and relies on
88 // private fields, so attempt to mimic serde's default impl for std
89 // Duration.
90 struct DurationProxy(chrono::Duration);
91 impl Serialize for DurationProxy {
92 fn serialize<S: ser::Serializer>(
93 &self,
94 serializer: S,
95 ) -> std::result::Result<S::Ok, S::Error> {
96 let mut s = serializer.serialize_struct(Duration::STRUCT_NAME, 2)?;
97 s.serialize_field(Duration::SECS_FIELD, &self.0.num_seconds())?;
98 s.serialize_field(
99 Duration::NANOS_FIELD,
100 &(self.0.num_nanoseconds().unwrap_or(0) % 1_000_000_000),
101 )?;
102 s.end()
103 }
104 }
105 serializer.serialize_newtype_struct(Self::NAME, &DurationProxy(self.0))
106 }
107}
108
109/// A wrapper Timestamp type which allows conversion to [Value::Timestamp] for

Callers 7

to_valueFunction · 0.45
serialize_someMethod · 0.45
serialize_keyMethod · 0.45
serialize_valueMethod · 0.45
serialize_fieldMethod · 0.45

Calls 5

DurationProxyClass · 0.85
serialize_structMethod · 0.80
serialize_fieldMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected