Skip to main content

feldera_types/
lib.rs

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