pub struct MacsecAn(/* private fields */);
Expand description
2 bit unsigned integer containing the “MACsec association number”.
(present in the crate::MacsecHeader
).
Identifies up to four SAs within the context of an SC.
Implementations§
Source§impl MacsecAn
impl MacsecAn
Sourcepub const fn try_new(value: u8) -> Result<MacsecAn, ValueTooBigError<u8>>
pub const fn try_new(value: u8) -> Result<MacsecAn, ValueTooBigError<u8>>
Tries to create an MacsecAn
and checks that the passed value
is smaller or equal than MacsecAn::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 MacsecAn
.
use etherparse::MacsecAn;
let an = MacsecAn::try_new(2).unwrap();
assert_eq!(an.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!(
MacsecAn::try_new(MacsecAn::MAX_U8 + 1),
Err(ValueTooBigError{
actual: MacsecAn::MAX_U8 + 1,
max_allowed: MacsecAn::MAX_U8,
value_type: ValueType::MacsecAn,
})
);
Sourcepub const unsafe fn new_unchecked(value: u8) -> MacsecAn
pub const unsafe fn new_unchecked(value: u8) -> MacsecAn
Creates an MacsecAn
without checking that the value
is smaller or equal than MacsecAn::MAX_U8
(2 bit unsigned integer).
The caller must guarantee that value <= MacsecAn::MAX_U8
.
§Safety
value
must be smaller or equal than MacsecAn::MAX_U8
otherwise the behavior of functions or data structures relying
on this pre-requirement is undefined.