rateslib/json/mod.rs
1//! Allows serialization and deserialization to JSON, with the ``serde`` crate.
2
3pub(crate) mod json_py;
4pub(crate) use crate::json::json_py::DeserializedObj;
5
6use serde::{Deserialize, Serialize};
7use serde_json;
8
9/// Handles the `to` and `from` JSON conversion.
10pub trait JSON: Serialize + for<'de> Deserialize<'de> {
11 /// Return a JSON string representing the object.
12 fn to_json(&self) -> serde_json::Result<String> {
13 serde_json::to_string(self)
14 }
15
16 /// Create an object from a JSON string representation.
17 fn from_json(json: &str) -> serde_json::Result<Self> {
18 serde_json::from_str(json)
19 }
20}