[−][src]Struct tide_validator::ValidatorMiddleware
Used as a middleware in your tide framework and add your custom validators
Methods
impl<T> ValidatorMiddleware<T> where
T: Serialize + Send + Sync + 'static,
[src]
T: Serialize + Send + Sync + 'static,
pub fn new() -> Self
[src]
Create a new ValidatorMiddleware to put in your tide configuration.
Example
ⓘThis example deliberately fails to compile
fn main() -> io::Result<()> { task::block_on(async { let mut app = tide::new(); let mut validator_middleware = ValidatorMiddleware::new(); validator_middleware.add_validator(HttpField::Header("X-Custom-Header"), is_number); app.at("/test/:n").middleware(validator_middleware).get( |_: tide::Request<()>| async move { tide::Response::new(StatusCode::Ok).body_json("test").unwrap() }, ); app.listen("127.0.0.1:8080").await?; Ok(()) }) }
pub fn with_validators<F>(
self,
validators: HashMap<HttpField<'static>, F>
) -> Self where
F: Fn(&str, Option<&str>) -> Result<(), T> + Send + Sync + 'static,
[src]
self,
validators: HashMap<HttpField<'static>, F>
) -> Self where
F: Fn(&str, Option<&str>) -> Result<(), T> + Send + Sync + 'static,
pub fn add_validator<F>(&mut self, param_name: HttpField<'static>, validator: F) where
F: Fn(&str, Option<&str>) -> Result<(), T> + Send + Sync + 'static,
[src]
F: Fn(&str, Option<&str>) -> Result<(), T> + Send + Sync + 'static,
Add new validator for your middleware
Example
ⓘThis example deliberately fails to compile
fn main() -> io::Result<()> { task::block_on(async { let mut app = tide::new(); let mut validator_middleware = ValidatorMiddleware::new(); validator_middleware.add_validator(HttpField::Header("X-Custom-Header"), is_number); validator_middleware.add_validator(HttpField::QueryParam("myqueryparam"), is_required); app.at("/test/:n").middleware(validator_middleware).get( |_: tide::Request<()>| async move { tide::Response::new(StatusCode::Ok).body_json("test").unwrap() }, ); app.listen("127.0.0.1:8080").await?; Ok(()) }) }
Trait Implementations
impl<State, T> Middleware<State> for ValidatorMiddleware<T> where
State: Send + Sync + 'static,
T: Serialize + Send + Sync + 'static,
[src]
State: Send + Sync + 'static,
T: Serialize + Send + Sync + 'static,
Auto Trait Implementations
impl<T> !RefUnwindSafe for ValidatorMiddleware<T>
impl<T> Send for ValidatorMiddleware<T>
impl<T> Sync for ValidatorMiddleware<T>
impl<T> Unpin for ValidatorMiddleware<T>
impl<T> !UnwindSafe for ValidatorMiddleware<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<State, F> Middleware<State> for F where
F: Send + Sync + 'static + for<'a> Fn(Request<State>, Next<'a, State>) -> Pin<Box<dyn Future<Output = Response> + 'a + Send>>,
[src]
F: Send + Sync + 'static + for<'a> Fn(Request<State>, Next<'a, State>) -> Pin<Box<dyn Future<Output = Response> + 'a + Send>>,
fn handle(
&'a self,
req: Request<State>,
next: Next<'a, State>
) -> Pin<Box<dyn Future<Output = Response> + 'a + Send>>
[src]
&'a self,
req: Request<State>,
next: Next<'a, State>
) -> Pin<Box<dyn Future<Output = Response> + 'a + Send>>
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,