[−][src]Struct zvariant::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]
fn slice_data(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
fn decode(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<Self, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<Self, VariantError>
fn ensure_correct_signature(
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
[src]
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
fn slice_signature(
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
[src]
signature: impl Into<Signature>
) -> Result<Signature, VariantError>
fn take_from_variant(variant: Variant) -> Result<Self, VariantError>
[src]
fn from_variant(variant: &Variant) -> Result<&Self, VariantError>
[src]
fn slice_for_decoding(
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
[src]
data: impl Into<SharedData>,
signature: impl Into<Signature>,
format: EncodingFormat
) -> Result<SharedData, VariantError>
impl Default for Array
[src]
impl Encode for Array
[src]
const SIGNATURE_CHAR: char
[src]
const SIGNATURE_STR: &'static str
[src]
const ALIGNMENT: usize
[src]
fn encode_into(&self, bytes: &mut Vec<u8>, format: EncodingFormat)
[src]
fn signature(&self) -> Signature
[src]
fn to_variant(self) -> Variant
[src]
fn is(variant: &Variant) -> bool
[src]
fn encode(&self, format: EncodingFormat) -> Vec<u8>
[src]
fn add_padding(bytes: &mut Vec<u8>, format: EncodingFormat)
[src]
fn padding(n_bytes_before: usize, _format: EncodingFormat) -> usize
[src]
impl From<Dict> for Array
[src]
impl<T> From<Vec<T>> for Array where
T: Encode,
[src]
T: Encode,
impl TryFrom<Array> for Dict
[src]
type Error = VariantError
The type returned in the event of a conversion error.
fn try_from(value: Array) -> Result<Self, VariantError>
[src]
impl<'a, T> TryInto<Vec<&'a T>> for &'a Array where
T: Decode,
[src]
T: Decode,
type Error = VariantError
The type returned in the event of a conversion error.
fn try_into(self) -> Result<Vec<&'a T>, VariantError>
[src]
impl<T> TryInto<Vec<T>> for Array where
T: Decode,
[src]
T: Decode,
type Error = VariantError
The type returned in the event of a conversion error.
fn try_into(self) -> Result<Vec<T>, VariantError>
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,