codama_nodes/
traits.rs

1use codama_errors::CodamaResult;
2use std::fmt::Debug;
3
4pub trait NodeTrait:
5    HasKind + Debug + PartialEq + Clone + serde::Serialize + for<'de> serde::Deserialize<'de>
6{
7    const KIND: &'static str;
8
9    fn to_json(&self) -> CodamaResult<String> {
10        serde_json::to_string(&self).map_err(Into::into)
11    }
12
13    fn to_json_pretty(&self) -> CodamaResult<String> {
14        serde_json::to_string_pretty(&self).map_err(Into::into)
15    }
16
17    fn from_json(json: &str) -> CodamaResult<Self> {
18        serde_json::from_str(json).map_err(Into::into)
19    }
20}
21
22pub trait NodeUnionTrait:
23    HasKind + Debug + PartialEq + Clone + serde::Serialize + for<'de> serde::Deserialize<'de>
24{
25}
26
27pub trait HasKind {
28    fn kind(&self) -> &'static str;
29}