pub struct VlanPcp(/* private fields */);Expand description
3 bit unsigned integer containing the “Priority Code Point”
(present in the crate::SingleVlanHeader).
Refers to the IEEE 802.1p class of service and maps to the frame priority level.
Implementations§
Source§impl VlanPcp
impl VlanPcp
Sourcepub const fn try_new(value: u8) -> Result<VlanPcp, ValueTooBigError<u8>>
pub const fn try_new(value: u8) -> Result<VlanPcp, ValueTooBigError<u8>>
Tries to create an VlanPcp and checks that the passed value
is smaller or equal than VlanPcp::MAX_U8 (3 bit unsigned integer).
In case the passed value is bigger then what can be represented in an 3 bit
integer an error is returned. Otherwise an Ok containing the VlanPcp.
use etherparse::VlanPcp;
let pcp = VlanPcp::try_new(2).unwrap();
assert_eq!(pcp.value(), 2);
// if a number that can not be represented in an 3 bit integer
// gets passed in an error is returned
use etherparse::err::{ValueTooBigError, ValueType};
assert_eq!(
VlanPcp::try_new(VlanPcp::MAX_U8 + 1),
Err(ValueTooBigError{
actual: VlanPcp::MAX_U8 + 1,
max_allowed: VlanPcp::MAX_U8,
value_type: ValueType::VlanPcp,
})
);Sourcepub const unsafe fn new_unchecked(value: u8) -> VlanPcp
pub const unsafe fn new_unchecked(value: u8) -> VlanPcp
Creates an VlanPcp without checking that the value
is smaller or equal than VlanPcp::MAX_U8 (3 bit unsigned integer).
The caller must guarantee that value <= VlanPcp::MAX_U8.
§Safety
value must be smaller or equal than VlanPcp::MAX_U8
otherwise the behavior of functions or data structures relying
on this pre-requirement is undefined.