Struct BinaryEncodedScope

Source
pub struct BinaryEncodedScope(/* private fields */);
Expand description

A scope encoded using a custom binary encoding. See Scope for more information.

§Example

Simply create a BinaryEncodedScope from a byte array (we’re using the byte 0x21 as a separator in this example):

let scope = BinaryEncodedScope::try_from(vec![0x00, 0x21, 0xDC, 0xAF].as_slice())?;
assert!(scope.elements(Some(0x21))?.eq(&vec![vec![0x00], vec![0xDC, 0xAF]]));

But note that the input array can’t be empty:

assert!(BinaryEncodedScope::try_from(vec![].as_slice()).is_err());

Implementations§

Source§

impl BinaryEncodedScope

Source

pub fn elements( &self, separator: Option<u8>, ) -> Result<Vec<&[u8]>, InvalidBinaryEncodedScopeError>

Return the individual elements (i.e., access ranges) of this scope.

If no separator is given (i.e. it is None), it is assumed that the scope consists of a single element and will be returned as such.

§Pre-conditions
  • If a separator is given, it may neither be the first nor last element of the scope.
  • If a separator is given, it may not occur twice in a row in the scope.
  • The scope must not be empty.
§Post-conditions
  • The returned vector will not be empty.
  • None of its elements will be empty.
  • If a separator is given, none of its elements will contain it.
  • If no separator is given, the vector will consist of a single element, containing the whole binary-encoded scope.
§Example
let simple = BinaryEncodedScope::try_from(vec![0xDC, 0x21, 0xAF].as_slice())?;
assert!(simple.elements(Some(0x21))?.eq(&vec![vec![0xDC], vec![0xAF]]));
assert!(simple.elements(None)?.eq(&vec![vec![0xDC, 0x21, 0xAF]]));
assert!(simple.elements(Some(0xDC)).is_err());
§Errors
  • If the binary encoded scope separated by the given separator is invalid in any way. This may be the case if:
    • The scope starts with a separator
    • The scope ends with a separator
    • The scope contains two separators in a row.
§Panics

If the pre-condition that the scope isn’t empty is violated. This shouldn’t occur, as it’s an invariant of BinaryEncodedScope.

Trait Implementations§

Source§

impl Clone for BinaryEncodedScope

Source§

fn clone(&self) -> BinaryEncodedScope

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BinaryEncodedScope

Source§

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

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

impl From<BinaryEncodedScope> for Scope

Source§

fn from(value: BinaryEncodedScope) -> Self

Converts to this type from the input type.
Source§

impl Hash for BinaryEncodedScope

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 PartialEq for BinaryEncodedScope

Source§

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

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

const 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 Serialize for BinaryEncodedScope

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&[u8]> for BinaryEncodedScope

Source§

type Error = InvalidBinaryEncodedScopeError

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 TryFrom<Scope> for BinaryEncodedScope

Source§

type Error = WrongSourceTypeError<Scope>

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

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

Performs the conversion.
Source§

impl Eq for BinaryEncodedScope

Source§

impl StructuralPartialEq for BinaryEncodedScope

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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

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, 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.