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