Skip to main content

conspire/constitutive/canonical/
mod.rs

1//! Constitutive models created through canonical compositions.
2
3use std::{
4    any::type_name,
5    fmt::{self, Debug, Formatter},
6};
7
8#[derive(Clone)]
9pub struct Canonical<C1, C2>(pub(crate) C1, pub(crate) C2);
10
11impl<C1, C2> From<(C1, C2)> for Canonical<C1, C2> {
12    fn from((constitutive_model_1, constitutive_model_2): (C1, C2)) -> Self {
13        Self(constitutive_model_1, constitutive_model_2)
14    }
15}
16
17impl<C1, C2> Debug for Canonical<C1, C2> {
18    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
19        write!(f, "Canonical({}, {})", base_name::<C1>(), base_name::<C2>())
20    }
21}
22
23fn base_name<T>() -> &'static str {
24    type_name::<T>()
25        .rsplit("::")
26        .next()
27        .unwrap()
28        .split('<')
29        .next()
30        .unwrap()
31}