Struct etherparse::VlanId
source · pub struct VlanId(/* private fields */);
Expand description
12 bit unsigned integer containing the “VLAN identifier” (present
in the crate::SingleVlanHeader
).
Implementations§
source§impl VlanId
impl VlanId
sourcepub const fn try_new(value: u16) -> Result<VlanId, ValueTooBigError<u16>>
pub const fn try_new(value: u16) -> Result<VlanId, ValueTooBigError<u16>>
Tries to create an VlanId
and checks that the passed value
is smaller or equal than VlanId::MAX_U16
(12 bit unsigned integer).
In case the passed value is bigger then what can be represented in an 12 bit
integer an error is returned. Otherwise an Ok
containing the VlanId
.
use etherparse::VlanId;
let vlanid = VlanId::try_new(2).unwrap();
assert_eq!(vlanid.value(), 2);
// if a number that can not be represented in an 12 bit integer
// gets passed in an error is returned
use etherparse::err::{ValueTooBigError, ValueType};
assert_eq!(
VlanId::try_new(VlanId::MAX_U16 + 1),
Err(ValueTooBigError{
actual: VlanId::MAX_U16 + 1,
max_allowed: VlanId::MAX_U16,
value_type: ValueType::VlanId,
})
);
sourcepub const unsafe fn new_unchecked(value: u16) -> VlanId
pub const unsafe fn new_unchecked(value: u16) -> VlanId
Creates an VlanId
WITHOUT checking that the value
is smaller or equal than VlanId::MAX_U16
(12 bit unsigned integer).
The caller must guarantee that value <= VlanId::MAX_U16
.
§Safety
value
must be smaller or equal than VlanId::MAX_U16
otherwise the behavior of functions or data structures relying
on this pre-requirement is undefined.
Trait Implementations§
source§impl Ord for VlanId
impl Ord for VlanId
source§impl PartialEq for VlanId
impl PartialEq for VlanId
source§impl PartialOrd for VlanId
impl PartialOrd for VlanId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for VlanId
impl Eq for VlanId
impl StructuralPartialEq for VlanId
Auto Trait Implementations§
impl Freeze for VlanId
impl RefUnwindSafe for VlanId
impl Send for VlanId
impl Sync for VlanId
impl Unpin for VlanId
impl UnwindSafe for VlanId
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