Struct etherparse::Ipv6FlowLabel
source · pub struct Ipv6FlowLabel(/* private fields */);
Expand description
The IPv6 “Flow Label” is a 20 bit unsigned integer present in
the crate::Ipv6Header
.
§Example Usage:
use etherparse::Ipv6FlowLabel;
// try into
{
let flow_label: Ipv6FlowLabel = 123.try_into().unwrap();
assert_eq!(flow_label.value(), 123);
// fragment offset can always be converted back to an u32
let value: u32 = flow_label.into();
assert_eq!(123, value);
}
// via try_new
{
let flow_label = Ipv6FlowLabel::try_new(123).unwrap();
assert_eq!(flow_label.value(), 123);
// note that only 20 bit numbers are allowed (meaning
// 0b1111_11111111_11111111 is the maximum allowed value)
use etherparse::err::{ValueTooBigError, ValueType};
assert_eq!(
Ipv6FlowLabel::try_new(Ipv6FlowLabel::MAX_U32 + 1),
Err(ValueTooBigError{
actual: Ipv6FlowLabel::MAX_U32 + 1,
max_allowed: Ipv6FlowLabel::MAX_U32,
value_type: ValueType::Ipv6FlowLabel,
})
);
}
// via new_unchecked
{
// in case you are sure the number does not exceed the max
// you can use the unsafe new_unchecked function
let flow_label = unsafe {
// please make sure that the value is not greater than Ipv6FlowLabel::MAX_U32
// before calling this method
Ipv6FlowLabel::new_unchecked(123)
};
assert_eq!(flow_label.value(), 123);
}
Implementations§
source§impl Ipv6FlowLabel
impl Ipv6FlowLabel
sourcepub const ZERO: Ipv6FlowLabel = _
pub const ZERO: Ipv6FlowLabel = _
Ipv6FlowLabel with value 0.
sourcepub const fn try_new(value: u32) -> Result<Ipv6FlowLabel, ValueTooBigError<u32>>
pub const fn try_new(value: u32) -> Result<Ipv6FlowLabel, ValueTooBigError<u32>>
Tries to create an Ipv6FlowLabel
and checks that the passed value
is smaller or equal than Ipv6FlowLabel::MAX_U32
(20 bit unsigned integer).
In case the passed value is bigger then what can be represented in an 20 bit
integer an error is returned. Otherwise an Ok
containing the Ipv6FlowLabel
.
use etherparse::Ipv6FlowLabel;
let frag_offset = Ipv6FlowLabel::try_new(123).unwrap();
assert_eq!(frag_offset.value(), 123);
// if a number that can not be represented in an 20 bit integer
// gets passed in an error is returned
use etherparse::err::{ValueTooBigError, ValueType};
assert_eq!(
Ipv6FlowLabel::try_new(Ipv6FlowLabel::MAX_U32 + 1),
Err(ValueTooBigError{
actual: Ipv6FlowLabel::MAX_U32 + 1,
max_allowed: Ipv6FlowLabel::MAX_U32,
value_type: ValueType::Ipv6FlowLabel,
})
);
sourcepub const unsafe fn new_unchecked(value: u32) -> Ipv6FlowLabel
pub const unsafe fn new_unchecked(value: u32) -> Ipv6FlowLabel
Creates an Ipv6FlowLabel
without checking that the value
is smaller or equal than Ipv6FlowLabel::MAX_U32
(20 bit unsigned integer).
The caller must guarantee that value <= Ipv6FlowLabel::MAX_U32
.
§Safety
value
must be smaller or equal than Ipv6FlowLabel::MAX_U32
otherwise the behavior of functions or data structures relying
on this pre-requirement is undefined.
Trait Implementations§
source§impl Clone for Ipv6FlowLabel
impl Clone for Ipv6FlowLabel
source§fn clone(&self) -> Ipv6FlowLabel
fn clone(&self) -> Ipv6FlowLabel
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Ipv6FlowLabel
impl Debug for Ipv6FlowLabel
source§impl Default for Ipv6FlowLabel
impl Default for Ipv6FlowLabel
source§fn default() -> Ipv6FlowLabel
fn default() -> Ipv6FlowLabel
source§impl Display for Ipv6FlowLabel
impl Display for Ipv6FlowLabel
source§impl From<Ipv6FlowLabel> for u32
impl From<Ipv6FlowLabel> for u32
source§fn from(value: Ipv6FlowLabel) -> Self
fn from(value: Ipv6FlowLabel) -> Self
source§impl Hash for Ipv6FlowLabel
impl Hash for Ipv6FlowLabel
source§impl Ord for Ipv6FlowLabel
impl Ord for Ipv6FlowLabel
source§fn cmp(&self, other: &Ipv6FlowLabel) -> Ordering
fn cmp(&self, other: &Ipv6FlowLabel) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for Ipv6FlowLabel
impl PartialEq for Ipv6FlowLabel
source§fn eq(&self, other: &Ipv6FlowLabel) -> bool
fn eq(&self, other: &Ipv6FlowLabel) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for Ipv6FlowLabel
impl PartialOrd for Ipv6FlowLabel
source§fn partial_cmp(&self, other: &Ipv6FlowLabel) -> Option<Ordering>
fn partial_cmp(&self, other: &Ipv6FlowLabel) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more