timsrust_core/coordinates/
converters.rs1pub trait Converter<Input, Output> {
2 fn convert(&self, value: Input) -> Output;
3
4 fn batch_convert(&self, values: &[Input]) -> Vec<Output>
5 where
6 Input: Clone,
7 {
8 values.iter().map(|v| self.convert(v.clone())).collect()
9 }
10}
11
12pub trait InvertibleConverter<Input, Output>:
13 Converter<Input, Output> + Converter<Output, Input>
14{
15}
16
17impl<Input, Output, T> InvertibleConverter<Input, Output> for T where
18 T: Converter<Input, Output> + Converter<Output, Input>
19{
20}
21
22pub trait ConvertibleTo<Output>: Sized + Copy {
23 fn convert<C: Converter<Self, Output>>(&self, converter: &C) -> Output {
24 converter.convert(*self)
25 }
26}
27
28impl<Input, Output, T> Converter<Input, Output> for &T
33where
34 T: Converter<Input, Output>,
35{
36 fn convert(&self, value: Input) -> Output {
37 (*self).convert(value)
38 }
39
40 }
47
48#[derive(Debug, Clone)]
49pub struct BitConverter();