Macro enso_flexer::prelude::logger::prelude::impls [−][src]
macro_rules! impls { ($([$($impl_params:tt)*])? From<$ty:ty> for $target:ty $(where [$($bounds:tt)*])? { |$arg:tt| $($result:tt)* } ) => { ... }; ($([$($impl_params:tt)*])? From + &From <$ty:ty> for $target:ty $(where [$($bounds:tt)*])? { |$arg:tt| $($result:tt)* } ) => { ... }; ($([$($impl_params:tt)*])? Into + &Into <$ty:ty> for $target:ty $(where [$($bounds:tt)*])? { |$arg:tt| $($result:tt)* } ) => { ... }; ($([$($impl_params:tt)*])? PhantomFrom<$ty:ty> for $target:ty { $($result:tt)* } ) => { ... }; }
Expand description
Allows for nicer definition of impls, similar to what Haskell or Scala does. Reduces the needed boilerplate. For example, the following usage:
ⓘ
struct A { name:String }; impls! { From<A> for String { |t| t.name.clone() } }
compiles to:
struct A { name:String }; impl From<A> for String { fn from(t:A) -> Self { t.name.clone() } }
This macro is meant to support many standard traits (like From) and should grow in the future. Currently supported ones are:
- From<…>
- From + &From<…>
- Into + &Into<…>
- PhantomFrom<…>