Skip to main content

Array

Struct Array 

Source
pub struct Array { /* private fields */ }
Expand description

Content of an array, CBOR major type 4.

An array holds an ordered sequence of data items and remembers whether it was encoded with a definite length or with the indefinite length form terminated by a break. The items themselves are reached through items and its mutable and owning counterparts.

§Example

use cbor_next::{Array, DataItem};

let mut content = Array::from_items([1, 2]);
content.extend([3]);
assert_eq!(content.items().len(), 3);
assert_eq!(content.items()[2], DataItem::from(3));
assert!(!content.is_indefinite());

Implementations§

Source§

impl Array

Source

pub fn new() -> Self

Create an empty definite length array.

Source

pub fn from_items<I, T>(items: I) -> Self
where I: IntoIterator<Item = T>, T: Into<DataItem>,

Create a definite length array from a sequence of items.

Source

pub fn with_indefinite(self, indefinite: bool) -> Self

Return the same content with the definite or indefinite encoding selected.

§Example
use cbor_next::Array;

let content = Array::from_items([1, 2]).with_indefinite(true);
assert!(content.is_indefinite());
Source

pub fn set_indefinite(&mut self, indefinite: bool)

Select the definite or indefinite encoding in place.

Source

pub fn is_indefinite(&self) -> bool

Whether the array uses the indefinite length encoding.

Source

pub fn items(&self) -> &[DataItem]

The items of the array.

Source

pub fn items_mut(&mut self) -> &mut Vec<DataItem>

The items of the array, mutably.

Source

pub fn into_items(self) -> Vec<DataItem>

Take ownership of the items of the array.

Trait Implementations§

Source§

impl Clone for Array

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Array

Source§

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

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

impl Default for Array

Source§

fn default() -> Self

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

impl Eq for Array

Source§

impl<T> Extend<T> for Array
where T: Into<DataItem>,

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<Array> for DataItem

Source§

fn from(value: Array) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for Array
where T: Into<DataItem>,

Source§

fn from(value: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, const N: usize> From<[T; N]> for Array
where T: Into<DataItem>,

Source§

fn from(value: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for Array
where T: Into<DataItem>,

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Array

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 Array

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Array

Auto Trait Implementations§

§

impl Freeze for Array

§

impl RefUnwindSafe for Array

§

impl Send for Array

§

impl Sync for Array

§

impl Unpin for Array

§

impl UnsafeUnpin for Array

§

impl UnwindSafe for Array

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.