pub struct IpFilter { /* private fields */ }Expand description
IP filter for restricting network communication to specific IP ranges using CIDR notation.
Implementations§
Source§impl IpFilter
impl IpFilter
Sourcepub const fn new(allowed_networks: Vec<IpNet>) -> Self
pub const fn new(allowed_networks: Vec<IpNet>) -> Self
Creates a new IP filter with the given CIDR networks.
If the list is empty, all IPs will be allowed.
Sourcepub fn from_cidr_string(cidrs: &str) -> Result<Self, AddrParseError>
pub fn from_cidr_string(cidrs: &str) -> Result<Self, AddrParseError>
Creates an IP filter from a comma-separated list of CIDR networks.
§Errors
Returns an error if any of the CIDR strings cannot be parsed.
Sourcepub fn is_allowed(&self, ip: &IpAddr) -> bool
pub fn is_allowed(&self, ip: &IpAddr) -> bool
Checks if the given IP address is allowed by this filter.
Returns true if the filter is empty (allows all) or if the IP is within
any of the allowed networks.
Sourcepub const fn has_restrictions(&self) -> bool
pub const fn has_restrictions(&self) -> bool
Returns true if this filter has restrictions (i.e., not allowing all IPs).
Sourcepub fn allowed_networks(&self) -> &[IpNet]
pub fn allowed_networks(&self) -> &[IpNet]
Returns the list of allowed networks.
Trait Implementations§
impl Eq for IpFilter
impl StructuralPartialEq for IpFilter
Auto Trait Implementations§
impl Freeze for IpFilter
impl RefUnwindSafe for IpFilter
impl Send for IpFilter
impl Sync for IpFilter
impl Unpin for IpFilter
impl UnwindSafe for IpFilter
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes