pub struct MacsecShortLen(/* private fields */);
Expand description
6 bit unsigned integer containing the “MACsec short length”.
(present in the crate::MacsecHeader
).
Implementations§
Source§impl MacsecShortLen
impl MacsecShortLen
Sourcepub const ZERO: MacsecShortLen
pub const ZERO: MacsecShortLen
MacsecShortLen with value 0.
Sourcepub const fn try_from_u8(
value: u8,
) -> Result<MacsecShortLen, ValueTooBigError<u8>>
pub const fn try_from_u8( value: u8, ) -> Result<MacsecShortLen, ValueTooBigError<u8>>
Tries to create an MacsecShortLen
and checks that the passed value
is smaller or equal than MacsecShortLen::MAX_U8
(6 bit unsigned integer).
In case the passed value is bigger then what can be represented in an 6 bit
integer an error is returned. Otherwise an Ok
containing the MacsecShortLen
.
use etherparse::MacsecShortLen;
let an = MacsecShortLen::try_from_u8(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!(
MacsecShortLen::try_from_u8(MacsecShortLen::MAX_U8 + 1),
Err(ValueTooBigError{
actual: MacsecShortLen::MAX_U8 + 1,
max_allowed: MacsecShortLen::MAX_U8,
value_type: ValueType::MacsecShortLen,
})
);
Sourcepub const unsafe fn from_u8_unchecked(value: u8) -> MacsecShortLen
pub const unsafe fn from_u8_unchecked(value: u8) -> MacsecShortLen
Creates an MacsecShortLen
without checking that the value
is smaller or equal than MacsecShortLen::MAX_U8
(6 bit unsigned integer).
The caller must guarantee that value <= MacsecShortLen::MAX_U8
.
§Safety
value
must be smaller or equal than MacsecShortLen::MAX_U8
otherwise the behavior of functions or data structures relying
on this pre-requirement is undefined.
Sourcepub fn from_len(len: usize) -> MacsecShortLen
pub fn from_len(len: usize) -> MacsecShortLen
Creates an MacsecShortLen
from a length and automatically
defaults to zero if too big. This mirrors the expected behavior
of the short_len
field in the crate::MacsecHeader
.
§Example
use etherparse::MacsecShortLen;
// if the length is smaller than 64.
let a = MacsecShortLen::from_len(34);
assert_eq!(34, a.value());
// if the length is greater than 64 [`MacsecShortLen::MAX_U8`]
// zero is returned
let b = MacsecShortLen::from_len(65);
assert_eq!(0, b.value());
Trait Implementations§
Source§impl Clone for MacsecShortLen
impl Clone for MacsecShortLen
Source§fn clone(&self) -> MacsecShortLen
fn clone(&self) -> MacsecShortLen
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more