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