Struct etherparse::Ipv4Ecn
source · pub struct Ipv4Ecn(/* private fields */);
Expand description
2 bit unsigned integer containing the “Explicit Congestion
Notification” (present in the crate::Ipv4Header
).
Implementations§
source§impl Ipv4Ecn
impl Ipv4Ecn
sourcepub const fn try_new(value: u8) -> Result<Ipv4Ecn, ValueTooBigError<u8>>
pub const fn try_new(value: u8) -> Result<Ipv4Ecn, ValueTooBigError<u8>>
Tries to create an Ipv4Ecn
and checks that the passed value
is smaller or equal than Ipv4Ecn::MAX_U8
(2 bit unsigned integer).
In case the passed value is bigger then what can be represented in an 2 bit
integer an error is returned. Otherwise an Ok
containing the Ipv4Ecn
.
use etherparse::Ipv4Ecn;
let ecn = Ipv4Ecn::try_new(2).unwrap();
assert_eq!(ecn.value(), 2);
// if a number that can not be represented in an 2 bit integer
// gets passed in an error is returned
use etherparse::err::{ValueTooBigError, ValueType};
assert_eq!(
Ipv4Ecn::try_new(Ipv4Ecn::MAX_U8 + 1),
Err(ValueTooBigError{
actual: Ipv4Ecn::MAX_U8 + 1,
max_allowed: Ipv4Ecn::MAX_U8,
value_type: ValueType::Ipv4Ecn,
})
);
sourcepub const unsafe fn new_unchecked(value: u8) -> Ipv4Ecn
pub const unsafe fn new_unchecked(value: u8) -> Ipv4Ecn
Creates an Ipv4Ecn
without checking that the value
is smaller or equal than Ipv4Ecn::MAX_U8
(2 bit unsigned integer).
The caller must guarantee that value <= Ipv4Ecn::MAX_U8
.
§Safety
value
must be smaller or equal than Ipv4Ecn::MAX_U8
otherwise the behavior of functions or data structures relying
on this pre-requirement is undefined.
Trait Implementations§
source§impl Ord for Ipv4Ecn
impl Ord for Ipv4Ecn
source§impl PartialEq for Ipv4Ecn
impl PartialEq for Ipv4Ecn
source§impl PartialOrd for Ipv4Ecn
impl PartialOrd for Ipv4Ecn
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 Ipv4Ecn
impl Eq for Ipv4Ecn
impl StructuralPartialEq for Ipv4Ecn
Auto Trait Implementations§
impl Freeze for Ipv4Ecn
impl RefUnwindSafe for Ipv4Ecn
impl Send for Ipv4Ecn
impl Sync for Ipv4Ecn
impl Unpin for Ipv4Ecn
impl UnwindSafe for Ipv4Ecn
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