[][src]Struct zvariant::Array

pub struct Array(_);

An unordered collection of items of the same type.

API is provided to transform this into, and from a Vec.

Methods

impl Array[src]

pub fn new() -> Self[src]

Creates a new empty Array.

pub fn new_from_vec(vec: Vec<Variant>) -> Result<Self, VariantError>[src]

Creates an Array from given variants.

All variants must all contain the same type.

Example:

use zvariant::{Array, Encode, Variant};

let variants = vec![42u8.to_variant(), 45u8.to_variant()];
let array = Array::new_from_vec(variants).unwrap();

let variants = vec![42u8.to_variant(), 45u32.to_variant()];
assert!(Array::new_from_vec(variants).is_err());

pub fn new_from_vec_unchecked(vec: Vec<Variant>) -> Self[src]

Creates an Array from given variants.

Same as new_from_vec but the caller guarantees all variants in the vec are of the same type.

pub fn add_element<T: Encode>(&mut self, element: T) -> Result<(), VariantError>[src]

Adds the given element to self.

Example:

use zvariant::{Array, Decode, Variant};

let mut array = Array::new();
array.add_element(42u8).unwrap();
assert!(array.add_element("hi").is_err());
array.add_element(45u8).unwrap();
assert!(array.add_element(42u32).is_err());

pub fn get_element<T: Decode>(&self, index: usize) -> Result<&T, VariantError>[src]

Get the element at the given index.

Example:

use zvariant::{Array, Decode, Variant};

let array = Array::from(vec![42u8, 43, 44]);
assert!(*array.get_element::<u8>(0).unwrap() == 42);
assert!(*array.get_element::<u8>(1).unwrap() == 43);
assert!(*array.get_element::<u8>(2).unwrap() == 44);

Trait Implementations

impl Clone for Array[src]

impl Debug for Array[src]

impl Decode for Array[src]

impl Default for Array[src]

impl Encode for Array[src]

impl From<Dict> for Array[src]

impl<T> From<Vec<T>> for Array where
    T: Encode
[src]

impl TryFrom<Array> for Dict[src]

type Error = VariantError

The type returned in the event of a conversion error.

impl<'a, T> TryInto<Vec<&'a T>> for &'a Array where
    T: Decode
[src]

type Error = VariantError

The type returned in the event of a conversion error.

impl<T> TryInto<Vec<T>> for Array where
    T: Decode
[src]

type Error = VariantError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Array

impl Send for Array

impl Sync for Array

impl Unpin for Array

impl UnwindSafe for Array

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.