impl_from.rs 527 B

12345678910111213141516171819
  1. /// Implements 'From' for a list of variants, intended for use with error enums
  2. /// that are wrapping a number of errors from other methods.
  3. #[macro_export]
  4. macro_rules! impl_from {
  5. (
  6. $enum_name: ident {
  7. $($error_type: ty => $variant_name: ident),* $(,)*
  8. }
  9. ) => {
  10. $(
  11. impl From<$error_type> for $enum_name {
  12. fn from(error: $error_type) -> $enum_name {
  13. $enum_name::$variant_name(error)
  14. }
  15. }
  16. )*
  17. }
  18. }