mirror of https://github.com/rwf2/Rocket.git
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:
parent
d92b7249cb
commit
f21da79f44
|
@ -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> {
|
|
||||||
fn from(choices: &'static [Cow<'v, str>; $size]) -> Self {
|
|
||||||
let choices = &choices[..];
|
let choices = &choices[..];
|
||||||
ErrorKind::InvalidChoice { choices: choices.into() }
|
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) => (
|
||||||
|
|
Loading…
Reference in New Issue