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