pub struct ValidatorMiddleware<T>{ /* private fields */ }
Expand description
Used as a middleware in your tide framework and add your custom validators
Implementations§
Source§impl<T> ValidatorMiddleware<T>
impl<T> ValidatorMiddleware<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ValidatorMiddleware to put in your tide configuration.
§Example
ⓘ
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 { Ok(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
Sourcepub fn add_validator<F>(&mut self, param_name: HttpField<'static>, validator: F)
pub fn add_validator<F>(&mut self, param_name: HttpField<'static>, validator: F)
Add new validator for your middleware
§Example
ⓘ
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 { Ok(tide::Response::new(StatusCode::Ok).body_json("test").unwrap()) },
);
app.listen("127.0.0.1:8080").await?;
Ok(())
})
}
Trait Implementations§
Source§impl<T> Debug for ValidatorMiddleware<T>
impl<T> Debug for ValidatorMiddleware<T>
Auto Trait Implementations§
impl<T> Freeze for ValidatorMiddleware<T>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more