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