1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
pub use self::{catalyst::*, specs::*};
pub(crate) mod catalyst;
pub(crate) mod specs {
use std::convert::Into;
pub trait Transformable<T>: Into<T> {}
pub trait Converter<S, T>
where
S: Clone + Transformable<T>,
{
fn data(&self) -> &[S];
fn catalyst(&mut self) -> Vec<T>
where
S: Iterator,
{
self.data()
.to_owned()
.iter()
.cloned()
.map(|i| i.into())
.collect::<Vec<_>>()
}
}
pub trait Transformation<S> {
fn data(&self) -> Vec<S>;
fn transform<T>(
&self,
catalyst: fn(&S) -> T,
) -> Result<Vec<T>, Box<dyn std::error::Error>> {
let res = self.data().iter().map(catalyst).collect::<Vec<_>>();
Ok(res)
}
}
}