improve docs for any and all guards

This commit is contained in:
Rob Ede 2021-12-28 00:45:38 +00:00
parent 14ccf67691
commit ae6cddf907
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 10 additions and 6 deletions

View File

@ -151,7 +151,7 @@ where
} }
} }
/// Return guard that matches if any of supplied guards. /// Creates a guard that matches if any added guards match.
/// ///
/// # Examples /// # Examples
/// The handler below will be called for either request method `GET` or `POST`. /// The handler below will be called for either request method `GET` or `POST`.
@ -171,13 +171,15 @@ pub fn Any<F: Guard + 'static>(guard: F) -> AnyGuard {
} }
} }
/// Matches any of supplied guards. /// A collection of guards that match if the disjunction of their `check` outcomes is true.
///
/// That is, only one contained guard needs to match in order for the aggregate guard to match.
pub struct AnyGuard { pub struct AnyGuard {
guards: Vec<Box<dyn Guard>>, guards: Vec<Box<dyn Guard>>,
} }
impl AnyGuard { impl AnyGuard {
/// Add guard to a list of guards to check /// Adds new guard to the collection of guards to check.
pub fn or<F: Guard + 'static>(mut self, guard: F) -> Self { pub fn or<F: Guard + 'static>(mut self, guard: F) -> Self {
self.guards.push(Box::new(guard)); self.guards.push(Box::new(guard));
self self
@ -196,7 +198,7 @@ impl Guard for AnyGuard {
} }
} }
/// Creates a guard that matches if all of the supplied guards. /// Creates a guard that matches if all added guards match.
/// ///
/// # Examples /// # Examples
/// The handler below will only be called if the request method is `GET` **and** the specified /// The handler below will only be called if the request method is `GET` **and** the specified
@ -218,13 +220,15 @@ pub fn All<F: Guard + 'static>(guard: F) -> AllGuard {
} }
} }
/// Matches if all of supplied guards. /// A collection of guards that match if the conjunction of their `check` outcomes is true.
///
/// That is, **all** contained guard needs to match in order for the aggregate guard to match.
pub struct AllGuard { pub struct AllGuard {
guards: Vec<Box<dyn Guard>>, guards: Vec<Box<dyn Guard>>,
} }
impl AllGuard { impl AllGuard {
/// Add new guard to the list of guards to check /// Adds new guard to the collection of guards to check.
pub fn and<F: Guard + 'static>(mut self, guard: F) -> Self { pub fn and<F: Guard + 'static>(mut self, guard: F) -> Self {
self.guards.push(Box::new(guard)); self.guards.push(Box::new(guard));
self self