typestuff/
transformable.rs

1use std::convert::Infallible;
2
3pub use typestuff_macro::transformable;
4
5pub trait Transformable: 'static {
6    const FIELDS: &'static [&'static dyn Field<Object = Self>];
7}
8
9pub trait Transformation {
10    type Map<F, T>
11    where
12        F: Field;
13}
14
15pub trait Transformer<Source, Destination>
16where
17    Source: Transformation,
18    Destination: Transformation,
19{
20    type Error;
21
22    fn map<F, T>(
23        &mut self,
24        value: Source::Map<F, T>,
25    ) -> Result<Destination::Map<F, T>, Self::Error>
26    where
27        F: Field;
28}
29
30pub trait Field {
31    type Object: Transformable;
32
33    fn get() -> Self
34    where
35        Self: Sized;
36
37    fn name(&self) -> &'static str;
38}
39
40impl Transformation for () {
41    type Map<F, T> = T
42    where
43        F: Field;
44}
45
46impl<Tr> Transformer<Tr, Tr> for ()
47where
48    Tr: Transformation,
49{
50    type Error = Infallible;
51
52    fn map<F, T>(&mut self, value: Tr::Map<F, T>) -> Result<Tr::Map<F, T>, Self::Error>
53    where
54        F: Field,
55    {
56        Ok(value)
57    }
58}