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
impl BinaryEncodedScope
Sourcepub fn elements(
&self,
separator: Option<u8>,
) -> Result<Vec<&[u8]>, InvalidBinaryEncodedScopeError>
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
impl Clone for BinaryEncodedScope
Source§fn clone(&self) -> BinaryEncodedScope
fn clone(&self) -> BinaryEncodedScope
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for BinaryEncodedScope
impl Debug for BinaryEncodedScope
Source§impl From<BinaryEncodedScope> for Scope
impl From<BinaryEncodedScope> for Scope
Source§fn from(value: BinaryEncodedScope) -> Self
fn from(value: BinaryEncodedScope) -> Self
Converts to this type from the input type.
Source§impl Hash for BinaryEncodedScope
impl Hash for BinaryEncodedScope
Source§impl PartialEq for BinaryEncodedScope
impl PartialEq for BinaryEncodedScope
Source§impl Serialize for BinaryEncodedScope
impl Serialize for BinaryEncodedScope
Source§impl TryFrom<&[u8]> for BinaryEncodedScope
impl TryFrom<&[u8]> for BinaryEncodedScope
Source§impl TryFrom<Scope> for BinaryEncodedScope
impl TryFrom<Scope> for BinaryEncodedScope
impl Eq for BinaryEncodedScope
impl StructuralPartialEq for BinaryEncodedScope
Auto Trait Implementations§
impl Freeze for BinaryEncodedScope
impl RefUnwindSafe for BinaryEncodedScope
impl Send for BinaryEncodedScope
impl Sync for BinaryEncodedScope
impl Unpin for BinaryEncodedScope
impl UnwindSafe for BinaryEncodedScope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more