Enum rcgen::CidrSubnet
source · [−]Expand description
CIDR subnet, as per RFC 4632
You might know CIDR subnets better by their textual representation
where they consist of an ip address followed by a slash and a prefix
number, for example 192.168.99.0/24
.
The first field in the enum is the address, the second is the mask. Both are specified in network byte order.
Variants
V4([u8; 4], [u8; 4])
V6([u8; 16], [u8; 16])
Implementations
sourceimpl CidrSubnet
impl CidrSubnet
sourcepub fn from_str(s: &str) -> Result<Self, ()>
pub fn from_str(s: &str) -> Result<Self, ()>
Obtains the CidrSubnet from the well-known addr/prefix notation.
// The "192.0.2.0/24" example from
// https://tools.ietf.org/html/rfc5280#page-42
let subnet = CidrSubnet::from_str("192.0.2.0/24").unwrap();
assert_eq!(subnet, CidrSubnet::V4([0xC0, 0x00, 0x02, 0x00], [0xFF, 0xFF, 0xFF, 0x00]));
sourcepub fn from_addr_prefix(addr: IpAddr, prefix: u8) -> Self
pub fn from_addr_prefix(addr: IpAddr, prefix: u8) -> Self
Obtains the CidrSubnet from an ip address as well as the specified prefix number.
// The "192.0.2.0/24" example from
// https://tools.ietf.org/html/rfc5280#page-42
let addr = IpAddr::from_str("192.0.2.0").unwrap();
let subnet = CidrSubnet::from_addr_prefix(addr, 24);
assert_eq!(subnet, CidrSubnet::V4([0xC0, 0x00, 0x02, 0x00], [0xFF, 0xFF, 0xFF, 0x00]));
Trait Implementations
sourceimpl Clone for CidrSubnet
impl Clone for CidrSubnet
sourcefn clone(&self) -> CidrSubnet
fn clone(&self) -> CidrSubnet
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for CidrSubnet
impl Debug for CidrSubnet
sourceimpl Hash for CidrSubnet
impl Hash for CidrSubnet
sourceimpl PartialEq<CidrSubnet> for CidrSubnet
impl PartialEq<CidrSubnet> for CidrSubnet
sourcefn eq(&self, other: &CidrSubnet) -> bool
fn eq(&self, other: &CidrSubnet) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &CidrSubnet) -> bool
fn ne(&self, other: &CidrSubnet) -> bool
This method tests for !=
.
impl Eq for CidrSubnet
impl StructuralEq for CidrSubnet
impl StructuralPartialEq for CidrSubnet
Auto Trait Implementations
impl RefUnwindSafe for CidrSubnet
impl Send for CidrSubnet
impl Sync for CidrSubnet
impl Unpin for CidrSubnet
impl UnwindSafe for CidrSubnet
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more