pub struct MethodSet { /* private fields */ }Expand description
A set of methods: one bit per Method, so a membership check is one
AND. For routers and for the Allow field of a 405 response.
Method::Other cannot be represented precisely: contains(Method::Other)
means “some extension method is allowed”, and
write_allow leaves it out.
§Examples
use http_net::{Method, MethodSet};
const READ: MethodSet = MethodSet::of(&[Method::Get, Method::Head]);
let allowed = READ.with(Method::Post);
assert!(allowed.contains(Method::Post));
assert!(!allowed.contains(Method::Delete));
let mut allow = Vec::new();
allowed.write_allow(&mut allow);
assert_eq!(allow, b"GET, HEAD, POST");Implementations§
Source§impl MethodSet
impl MethodSet
Sourcepub const fn of(methods: &[Method]) -> Self
pub const fn of(methods: &[Method]) -> Self
The set of methods.
§Examples
use http_net::{Method, MethodSet};
let set = MethodSet::of(&[Method::Put, Method::Delete, Method::Put]);
assert_eq!(set.iter().count(), 2);Sourcepub const fn with(self, method: Method) -> Self
pub const fn with(self, method: Method) -> Self
This set with method added.
§Examples
use http_net::{Method, MethodSet};
assert!(MethodSet::EMPTY.with(Method::Get).contains(Method::Get));Sourcepub const fn contains(&self, method: Method) -> bool
pub const fn contains(&self, method: Method) -> bool
Whether method is in the set.
§Examples
use http_net::{Method, MethodSet};
assert!(!MethodSet::EMPTY.contains(Method::Get));Sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
The methods in either set.
§Examples
use http_net::{Method, MethodSet};
let both = MethodSet::of(&[Method::Get]).union(MethodSet::of(&[Method::Post]));
assert!(both.contains(Method::Get) && both.contains(Method::Post));Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Whether the set is empty.
§Examples
use http_net::{Method, MethodSet};
assert!(!MethodSet::of(&[Method::Get]).is_empty());Sourcepub fn iter(&self) -> impl Iterator<Item = Method> + use<>
pub fn iter(&self) -> impl Iterator<Item = Method> + use<>
The members in Method::index order.
§Examples
use http_net::{Method, MethodSet};
let set = MethodSet::of(&[Method::Post, Method::Get]);
assert_eq!(set.iter().collect::<Vec<_>>(), [Method::Get, Method::Post]);Sourcepub fn write_allow(&self, out: &mut Vec<u8>)
pub fn write_allow(&self, out: &mut Vec<u8>)
Appends the registered members to out as an Allow field value,
in Method::index order, separated by ", ". Other is left out
(it has no name to write).
§Examples
use http_net::{Method, MethodSet};
let mut out = Vec::new();
MethodSet::of(&[Method::Options, Method::Get, Method::Other]).write_allow(&mut out);
assert_eq!(out, b"GET, OPTIONS");Trait Implementations§
impl Copy for MethodSet
impl Eq for MethodSet
impl StructuralPartialEq for MethodSet
Auto Trait Implementations§
impl Freeze for MethodSet
impl RefUnwindSafe for MethodSet
impl Send for MethodSet
impl Sync for MethodSet
impl Unpin for MethodSet
impl UnsafeUnpin for MethodSet
impl UnwindSafe for MethodSet
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