pub trait SerializableCopula:
Copula
+ Serialize
+ for<'de> Deserialize<'de> {
// Provided methods
fn to_json(&self) -> Result<String> { ... }
fn from_json(json: &str) -> Result<Self>
where Self: Sized { ... }
}Available on crate feature
serde only.Expand description
JSON serialization for copula models.
Implemented by the core copula types when the serde feature is enabled.
A copula serializes to its parameters, and deserialization validates them
through the type’s constructor, so invalid parameters are rejected.
§Examples
use copula_core::traits::SerializableCopula;
use copula_core::ClaytonCopula;
let copula = ClaytonCopula::new(2.0)?;
let json = copula.to_json()?;
assert_eq!(json, r#"{"theta":2.0}"#);
let restored = ClaytonCopula::from_json(&json)?;
assert_eq!(restored.to_json()?, json);
// Deserialization applies the same validation as `ClaytonCopula::new`.
assert!(ClaytonCopula::from_json(r#"{"theta":-1.0}"#).is_err());Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".