haar_lib/macros/
convert.rs1#[macro_export]
5macro_rules! impl_from {
6 ($(#[$meta:meta])* [ $($t:tt)* ]; $from:ty => $into:ty, $f:expr) => {
7 impl<$($t)*> From<$from> for $into {
8 $(#[$meta])*
9 fn from(value: $from) -> Self {
10 $f(value)
11 }
12 }
13 };
14 ($(#[$meta:meta])* $from:ty => $into:ty, $f:expr) => {
15 impl_from!($(#[$meta])* []; $from => $into, $f);
16 };
17}
18
19#[macro_export]
21macro_rules! impl_try_from {
22 ($(#[$meta:meta])* [ $($t:tt)* ]; $from:ty => $into:ty, type Error = $error:ty, $f:expr) => {
23 impl<$($t)*> TryFrom<$from> for $into {
24 type Error = $error;
25 $(#[$meta])*
26 fn try_from(value: $from) -> Result<Self, Self::Error> {
27 $f(value)
28 }
29 }
30 };
31 ($(#[$meta:meta])* $from:ty => $into:ty, type Error = $error:ty, $f:expr) => {
32 impl_try_from!($(#[$meta])* []; $from => $into, type Error = $error, $f);
33 };
34}