mirror of https://github.com/rwf2/Rocket.git
Implement 'FromParam' for 'NonZero*' types.
This commit is contained in:
parent
cd92532909
commit
40f267c580
|
@ -1,5 +1,9 @@
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr};
|
||||||
|
use std::num::{
|
||||||
|
NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize,
|
||||||
|
NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, NonZeroUsize,
|
||||||
|
};
|
||||||
|
|
||||||
use http::RawStr;
|
use http::RawStr;
|
||||||
|
|
||||||
|
@ -77,9 +81,14 @@ use http::RawStr;
|
||||||
/// Rocket implements `FromFormValue` for many standard library types. Their
|
/// Rocket implements `FromFormValue` for many standard library types. Their
|
||||||
/// behavior is documented here.
|
/// behavior is documented here.
|
||||||
///
|
///
|
||||||
/// * **f32, f64, isize, i8, i16, i32, i64, i128, usize, u8, u16, u32, u64,
|
/// *
|
||||||
/// u128, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6,
|
/// * Primitive types: **f32, f64, isize, i8, i16, i32, i64, i128,
|
||||||
/// SocketAddr**
|
/// usize, u8, u16, u32, u64, u128**
|
||||||
|
/// * `IpAddr` and `SocketAddr` types: **IpAddr, Ipv4Addr, Ipv6Addr,
|
||||||
|
/// SocketAddrV4, SocketAddrV6, SocketAddr**
|
||||||
|
/// * `NonZero*` types: **NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64,
|
||||||
|
/// NonZeroI128, NonZeroIsize, NonZeroU8, NonZeroU16, NonZeroU32,
|
||||||
|
/// NonZeroU64, NonZeroU128, NonZeroUsize**
|
||||||
///
|
///
|
||||||
/// A value is validated successfully if the `from_str` method for the given
|
/// A value is validated successfully if the `from_str` method for the given
|
||||||
/// type returns successfully. Otherwise, the raw form value is returned as
|
/// type returns successfully. Otherwise, the raw form value is returned as
|
||||||
|
@ -231,9 +240,12 @@ macro_rules! impl_with_fromstr {
|
||||||
)+)
|
)+)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_with_fromstr!(f32, f64, isize, i8, i16, i32, i64, i128, usize, u8, u16,
|
impl_with_fromstr!(
|
||||||
u32, u64, u128, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6,
|
f32, f64, isize, i8, i16, i32, i64, i128, usize, u8, u16, u32, u64, u128,
|
||||||
SocketAddr);
|
NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize,
|
||||||
|
NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, NonZeroUsize,
|
||||||
|
IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr
|
||||||
|
);
|
||||||
|
|
||||||
impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Option<T> {
|
impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Option<T> {
|
||||||
type Error = !;
|
type Error = !;
|
||||||
|
|
|
@ -72,9 +72,14 @@ use http::{RawStr, uri::{Segments, SegmentError}};
|
||||||
/// Rocket implements `FromParam` for several standard library types. Their
|
/// Rocket implements `FromParam` for several standard library types. Their
|
||||||
/// behavior is documented here.
|
/// behavior is documented here.
|
||||||
///
|
///
|
||||||
/// * **f32, f64, isize, i8, i16, i32, i64, i128, usize, u8, u16, u32, u64,
|
/// *
|
||||||
/// u128, bool, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6,
|
/// * Primitive types: **f32, f64, isize, i8, i16, i32, i64, i128,
|
||||||
/// SocketAddr**
|
/// usize, u8, u16, u32, u64, u128, bool**
|
||||||
|
/// * `IpAddr` and `SocketAddr` types: **IpAddr, Ipv4Addr, Ipv6Addr,
|
||||||
|
/// SocketAddrV4, SocketAddrV6, SocketAddr**
|
||||||
|
/// * `NonZero*` types: **NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64,
|
||||||
|
/// NonZeroI128, NonZeroIsize, NonZeroU8, NonZeroU16, NonZeroU32,
|
||||||
|
/// NonZeroU64, NonZeroU128, NonZeroUsize**
|
||||||
///
|
///
|
||||||
/// A value is parsed successfully if the `from_str` method from the given
|
/// A value is parsed successfully if the `from_str` method from the given
|
||||||
/// type returns successfully. Otherwise, the raw path segment is returned
|
/// type returns successfully. Otherwise, the raw path segment is returned
|
||||||
|
@ -239,10 +244,16 @@ macro_rules! impl_with_fromstr {
|
||||||
)+)
|
)+)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use std::num::{
|
||||||
|
NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize,
|
||||||
|
NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, NonZeroUsize,
|
||||||
|
};
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr};
|
||||||
|
|
||||||
impl_with_fromstr! {
|
impl_with_fromstr! {
|
||||||
i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize, f32, f64,
|
i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize, f32, f64,
|
||||||
|
NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize,
|
||||||
|
NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, NonZeroUsize,
|
||||||
bool, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr
|
bool, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue