Trait domain::base::octets::OctetsRef[][src]

pub trait OctetsRef: AsRef<[u8]> + Copy + Sized {
    type Range: AsRef<[u8]>;
    fn range(self, start: usize, end: usize) -> Self::Range;

    fn range_from(self, start: usize) -> Self::Range { ... }
fn range_to(self, end: usize) -> Self::Range { ... }
fn range_all(self) -> Self::Range { ... } }

A reference to an octets sequence.

This trait is to be implemented for a (imutable) reference to a type of an octets sequence. I.e., it T is an octets sequence, OctetsRef needs to be implemented for &T.

The primary purpose of the trait is to allow access to a sub-sequence, called a ‘range.’ The type of this range is given via the Range associated type. For most types it will be a &[u8] with a lifetime equal to that of the reference itself. Only if an owned range can be created cheaply, it should be that type.

There is two basic ways of using the trait for a trait bound. You can either limit the octets sequence type itself by bounding references to it via a where clause. I.e., for an octets sequence type argument Octets you can specify where &'a Octets: OctetsRef or, if you don’t have a lifetime argument available where for<'a> &'a Octets: OctetsRef. For this option, you’d typically refer to values as references to the octets type, i.e., &Octets.

Alternatively, you can refer to the reference itself as a owned value. This works out fine since all octets references are required to be Copy. For instance, a function can take a value of generic type Oref and that type can then be directly bounded via Oref: OctetsRef.

Associated Types

type Range: AsRef<[u8]>[src]

The type of a range of the sequence.

Loading content...

Required methods

fn range(self, start: usize, end: usize) -> Self::Range[src]

Returns a sub-sequence or ‘range’ of the sequence.

Loading content...

Provided methods

fn range_from(self, start: usize) -> Self::Range[src]

Returns a range starting at index start and going to the end.

fn range_to(self, end: usize) -> Self::Range[src]

Returns a range from the start to before index end.

fn range_all(self) -> Self::Range[src]

Returns a range that covers the entire sequence.

Loading content...

Implementations on Foreign Types

impl<'a, T: OctetsRef> OctetsRef for &'a T[src]

type Range = T::Range

impl<'a> OctetsRef for &'a [u8][src]

type Range = &'a [u8]

impl<'a, 's> OctetsRef for &'a Cow<'s, [u8]>[src]

type Range = &'a [u8]

impl<'a> OctetsRef for &'a Vec<u8>[src]

type Range = &'a [u8]

Loading content...

Implementors

Loading content...