mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Don't copy-paste impl_froms
into every crate
This commit is contained in:
parent
6b4cf5b7d8
commit
693ac892f2
12 changed files with 69 additions and 106 deletions
|
@ -17,3 +17,24 @@ macro_rules! format_to {
|
|||
{ use ::std::fmt::Write as _; let _ = ::std::write!($buf, $lit $($arg)*); }
|
||||
};
|
||||
}
|
||||
|
||||
// Generates `From` impls for `Enum E { Foo(Foo), Bar(Bar) }` enums
|
||||
#[macro_export]
|
||||
macro_rules! impl_from {
|
||||
($($variant:ident $(($($sub_variant:ident),*))?),* for $enum:ident) => {
|
||||
$(
|
||||
impl From<$variant> for $enum {
|
||||
fn from(it: $variant) -> $enum {
|
||||
$enum::$variant(it)
|
||||
}
|
||||
}
|
||||
$($(
|
||||
impl From<$sub_variant> for $enum {
|
||||
fn from(it: $sub_variant) -> $enum {
|
||||
$enum::$variant($variant::$sub_variant(it))
|
||||
}
|
||||
}
|
||||
)*)?
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue