PropertiesBuf

Struct PropertiesBuf 

pub struct PropertiesBuf<P: PropertyConstraint> {
    _marker: PhantomData<P>,
    bytes: Vec<u8>,
}
Available on crate feature alloc only.
Expand description

Owned property bytes, the owned counterpart to Properties<P>.

Fields§

§_marker: PhantomData<P>§bytes: Vec<u8>

Implementations§

§

impl<P: PropertyConstraint> PropertiesBuf<P>

pub const fn new() -> Self

Creates an empty property buffer.

pub const fn as_properties(&self) -> &Properties<P>

Returns a reference to the underlying Properties<P>.

pub fn push(&mut self, prop: Property<'_>) -> Result<(), PropertiesBufError>

Appends a property to the buffer.

§Errors

Returns PropertiesBufError::DisallowedProperty if the property’s identifier is not in P::ALLOWED, or PropertiesBufError::TooLong if appending would exceed Vbi::MAX.

pub fn try_extend<'a>( &mut self, iter: impl IntoIterator<Item = Property<'a>>, ) -> Result<(), PropertiesBufError>

Extends this buffer with all properties from an iterator.

§Errors

Returns PropertiesBufError on the first disallowed or over-length property. Properties pushed before the error remain.

pub fn try_from_iter<'a>( iter: impl IntoIterator<Item = Property<'a>>, ) -> Result<Self, PropertiesBufError>

Collects properties from an iterator into a new buffer.

§Errors

Returns PropertiesBufError if any property’s identifier is not in P::ALLOWED or the result would exceed Vbi::MAX.

Methods from Deref<Target = Properties<P>>§

pub const EMPTY: &'static Self

pub fn is_empty(&self) -> bool

Returns true if there are no properties.

pub fn as_bytes(&self) -> &[u8]

Returns the raw bytes of the properties section.

pub fn iter(&self) -> PropertiesIter<'_>

Returns an iterator over the properties in this section.

pub fn find(&self, id: PropertyId) -> Option<Property<'_>>

Find the first occurrence of a property by identifier.

This is a linear scan over all properties.

pub fn collect_ids(&self) -> PropertyIdSet

Collects the set of property ids present in this section.

The word “collect” is used to indicate that this is a linear scan over all properties.

fn len_vbi(&self) -> Vbi

pub fn encoded_len(&self) -> usize

Returns the number of bytes needed to encode this properties section including the leading variable byte integer length prefix.

pub fn encode(&self, w: &mut Writer<'_>) -> Result<(), EncodeError>

Encodes this properties section into the writer, including the leading variable byte integer length prefix.

§Errors

Returns EncodeError if the writer does not have enough capacity.

Trait Implementations§

§

impl<P: PropertyConstraint> AsRef<Properties<P>> for PropertiesBuf<P>

§

fn as_ref(&self) -> &Properties<P>

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

impl<P: PropertyConstraint> Borrow<Properties<P>> for PropertiesBuf<P>

§

fn borrow(&self) -> &Properties<P>

Immutably borrows from an owned value. Read more
§

impl<P: PropertyConstraint> Clone for PropertiesBuf<P>

§

fn clone(&self) -> Self

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
§

impl<P: PropertyConstraint> Debug for PropertiesBuf<P>

§

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

Formats the value using the given formatter. Read more
§

impl<P: PropertyConstraint> Default for PropertiesBuf<P>

§

fn default() -> Self

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

impl<P: PropertyConstraint> Deref for PropertiesBuf<P>

§

type Target = Properties<P>

The resulting type after dereferencing.
§

fn deref(&self) -> &Properties<P>

Dereferences the value.
§

impl<P: PropertyConstraint> Hash for PropertiesBuf<P>

§

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
§

impl<P: PropertyConstraint, Q: PropertyConstraint> PartialEq<PropertiesBuf<Q>> for PropertiesBuf<P>

§

fn eq(&self, other: &PropertiesBuf<Q>) -> 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.
§

impl<'a, P: PropertyConstraint> TryFrom<&[Option<Property<'a>>]> for PropertiesBuf<P>

§

fn try_from(value: &[Option<Property<'a>>]) -> Result<Self, Self::Error>

Builds a PropertiesBuf from a slice of optional properties, skipping Nones.

§Errors

Returns PropertiesBufError if any present property’s identifier is not in P::ALLOWED, or if the encoded properties would exceed Vbi::MAX.

§

type Error = PropertiesBufError

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

impl<'a, P: PropertyConstraint> TryFrom<&[Property<'a>]> for PropertiesBuf<P>

§

fn try_from(value: &[Property<'a>]) -> Result<Self, Self::Error>

Builds a PropertiesBuf from a slice of properties.

§Errors

Returns PropertiesBufError if any property’s identifier is not in P::ALLOWED, or if the encoded properties would exceed Vbi::MAX.

§

type Error = PropertiesBufError

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

impl<P: PropertyConstraint> Eq for PropertiesBuf<P>

Auto Trait Implementations§

§

impl<P> Freeze for PropertiesBuf<P>

§

impl<P> RefUnwindSafe for PropertiesBuf<P>
where P: RefUnwindSafe,

§

impl<P> Send for PropertiesBuf<P>
where P: Send,

§

impl<P> Sync for PropertiesBuf<P>
where P: Sync,

§

impl<P> Unpin for PropertiesBuf<P>
where P: Unpin,

§

impl<P> UnwindSafe for PropertiesBuf<P>
where P: UnwindSafe,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.