Thanks to visit codestin.com
Credit goes to docs.rs

Struct MacsecShortLen

Source
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

Source

pub const ZERO: MacsecShortLen

MacsecShortLen with value 0.

Source

pub const MAX_U8: u8 = 63u8

Maximum value of a “MACsec short length” as a u8.

Source

pub const MAX_USIZE: usize = 63usize

Maximum value of a “MACsec short length” as a usize.

Source

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,
    })
);
Source

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.

Source

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());
Source

pub const fn value(self) -> u8

Returns the underlying unsigned 6 bit value as an u8 value.

Trait Implementations§

Source§

impl Clone for MacsecShortLen

Source§

fn clone(&self) -> MacsecShortLen

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MacsecShortLen

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MacsecShortLen

Source§

fn default() -> MacsecShortLen

Returns the “default value” for a type. Read more
Source§

impl Display for MacsecShortLen

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<MacsecShortLen> for u8

Source§

fn from(value: MacsecShortLen) -> Self

Converts to this type from the input type.
Source§

impl Hash for MacsecShortLen

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for MacsecShortLen

Source§

fn cmp(&self, other: &MacsecShortLen) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for MacsecShortLen

Source§

fn eq(&self, other: &MacsecShortLen) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for MacsecShortLen

Source§

fn partial_cmp(&self, other: &MacsecShortLen) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<u8> for MacsecShortLen

Source§

type Error = ValueTooBigError<u8>

The type returned in the event of a conversion error.
Source§

fn try_from(value: u8) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for MacsecShortLen

Source§

impl Eq for MacsecShortLen

Source§

impl StructuralPartialEq for MacsecShortLen

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.