Make 'form::ErrorKind' 'From' impl const generic.

Converts an older style array impl to one that uses const generics,
allowing any array length, not just a few sizes.
This commit is contained in:
Matthew Pomes 2022-05-18 22:39:51 -05:00 committed by Sergio Benitez
parent d92b7249cb
commit f21da79f44
1 changed files with 5 additions and 10 deletions

View File

@ -947,18 +947,13 @@ impl From<(Option<ByteUnit>, Option<ByteUnit>)> for ErrorKind<'_> {
} }
} }
macro_rules! impl_from_choices { impl<'a, 'v: 'a, const N: usize> From<&'static [Cow<'v, str>; N]> for ErrorKind<'a> {
($($size:literal),*) => ($( fn from(choices: &'static [Cow<'v, str>; N]) -> Self {
impl<'a, 'v: 'a> From<&'static [Cow<'v, str>; $size]> for ErrorKind<'a> { let choices = &choices[..];
fn from(choices: &'static [Cow<'v, str>; $size]) -> Self { ErrorKind::InvalidChoice { choices: choices.into() }
let choices = &choices[..]; }
ErrorKind::InvalidChoice { choices: choices.into() }
}
}
)*)
} }
impl_from_choices!(1, 2, 3, 4, 5, 6, 7, 8);
macro_rules! impl_from_for { macro_rules! impl_from_for {
(<$l:lifetime> $T:ty => $V:ty as $variant:ident) => ( (<$l:lifetime> $T:ty => $V:ty as $variant:ident) => (