Skip to main content

feldera_types/
lib.rs

1pub mod adapter_stats;
2pub mod checkpoint;
3pub mod completion_token;
4pub mod config;
5pub mod constants;
6pub mod coordination;
7pub mod error;
8pub mod format;
9pub mod pipeline_diff;
10pub mod preprocess;
11pub mod program_schema;
12pub mod query;
13pub mod query_params;
14pub mod runtime_status;
15pub mod secret_ref;
16pub mod secret_resolver;
17pub mod serde_with_context;
18pub mod suspend;
19pub mod time_series;
20pub mod transaction;
21pub mod transport;
22
23mod serde_via_value {
24    use serde::{
25        Deserialize, Deserializer, Serialize, Serializer,
26        de::{DeserializeOwned, Error},
27        ser::Error as _,
28    };
29
30    /// Use this as a serde deserialization function to work around
31    /// [`serde_json` issues] with nested `f64`.  It works in two steps, first
32    /// deserializing a `serde_json::Value` from `deserializer`, then
33    /// deserializing `T` from that `serde_json::Value`.
34    ///
35    /// Use this and `serialize` as serde de/serialization functions to work
36    /// around [`serde_yaml` issues] deserializing an enum variant with a
37    /// payload that is enclosed directly or indirectly within a flattened
38    /// struct.
39    ///
40    /// [`serde_json` issues]: https://github.com/serde-rs/json/issues/1157
41    /// [`serde_yaml` issues]: https://github.com/dtolnay/serde-yaml/issues/395
42    pub fn deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error>
43    where
44        D: Deserializer<'de>,
45        T: DeserializeOwned,
46    {
47        serde_json::from_value(serde_json::Value::deserialize(deserializer)?)
48            .map_err(D::Error::custom)
49    }
50
51    pub fn serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
52    where
53        T: Serialize,
54        S: Serializer,
55    {
56        serde_json::to_value(value)
57            .map_err(S::Error::custom)?
58            .serialize(serializer)
59    }
60}