Skip to main content

BytesRef

Struct BytesRef 

Source
#[repr(transparent)]
pub(crate) struct BytesRef([u8]);
Expand description

Byte slice newtype which respects the Length::MAX limit.

Tuple Fields§

§0: [u8]

Implementations§

Source§

impl BytesRef

Source

pub const EMPTY: &'static Self

Constant value representing an empty byte slice.

Source

pub const fn new(slice: &[u8]) -> Result<&Self>

Create a new BytesRef, ensuring that the provided slice value is shorter than Length::MAX.

Source

pub(crate) const fn new_unchecked(slice: &[u8]) -> &Self

Perform a raw conversion of a byte slice to Self without first performing a length check.

Source

pub(crate) const fn as_ptr(&self) -> *const BytesRef

Get a pointer to this BytesRef.

Source

pub const fn as_slice(&self) -> &[u8]

Borrow the inner byte slice

Source

pub fn len(&self) -> Length

Get the Length of this BytesRef.

Source

pub const fn is_empty(&self) -> bool

Is this BytesRef empty?

Source

pub fn prefix(&self, length: Length) -> Result<&Self>

Get a prefix of a [crate::bytes_ref::BytesRef] of the given length.

Trait Implementations§

Source§

impl AsRef<[u8]> for BytesRef

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<BytesRef> for BytesOwned

Source§

fn as_ref(&self) -> &BytesRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<BytesRef> for StringOwned

Source§

fn as_ref(&self) -> &BytesRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<BytesRef> for StringRef

Source§

fn as_ref(&self) -> &BytesRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<BytesRef> for BytesOwned

Source§

fn borrow(&self) -> &BytesRef

Immutably borrows from an owned value. Read more
Source§

impl Debug for BytesRef

Source§

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

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

impl<'a> DecodeValue<'a> for &'a BytesRef

Source§

type Error = Error

Type returned in the event of a decoding error.
Source§

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self>

Attempt to decode this value using the provided Reader. Read more
Source§

impl DerOrd for BytesRef

Source§

fn der_cmp(&self, other: &Self) -> Result<Ordering>

Return an Ordering between self and other when serialized as ASN.1 DER. Read more
Source§

impl EncodeValue for BytesRef

Source§

fn value_len(&self) -> Result<Length>

Compute the length of this value (sans Tag+Length header) when encoded as ASN.1 DER. Read more
Source§

fn encode_value(&self, writer: &mut impl Writer) -> Result<()>

Encode value (sans Tag+Length header) as ASN.1 DER using the provided Writer. Read more
Source§

impl From<&BytesRef> for BytesOwned

Source§

fn from(bytes: &BytesRef) -> BytesOwned

Converts to this type from the input type.
Source§

impl<'a> From<AnyRef<'a>> for &'a BytesRef

Source§

fn from(any: AnyRef<'a>) -> &'a BytesRef

Converts to this type from the input type.
Source§

impl Hash for BytesRef

Source§

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

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

impl Ord for BytesRef

Source§

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

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

impl PartialEq for BytesRef

Source§

fn eq(&self, other: &BytesRef) -> 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 BytesRef

Source§

fn partial_cmp(&self, other: &BytesRef) -> 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 ToOwned for BytesRef

Source§

type Owned = BytesOwned

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> BytesOwned

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

fn clone_into(&self, target: &mut Self::Owned)

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

impl<'a> TryFrom<&'a [u8]> for &'a BytesRef

Source§

type Error = Error

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

fn try_from(slice: &'a [u8]) -> Result<Self>

Performs the conversion.
Source§

impl Eq for BytesRef

Source§

impl StructuralPartialEq for BytesRef

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