[][src]Struct flatdata::ArrayView

pub struct ArrayView<'a, T> where
    T: for<'b> Struct<'b>, 
{ /* fields omitted */ }

A read-only view on a contiguous sequence of flatdata structs of the same type T.

The sequence is written using Vector or ExternalVector. The former provides a method to create an ArrayView to it. Note that, that an array view does not hold the data itself.

An archive provides a getter for each vector resource, which returns an array view.

Examples

use flatdata::{ArrayView, Vector};

define_struct!(
    A,
    RefA,
    RefMutA,
    "no_schema",
    4,
    (x, set_x, u32, 0, 16),
    (y, set_y, u32, 16, 16)
);

let mut v: Vector<A> = Vector::with_len(1);
{
    let mut a = v.at_mut(0);
    a.set_x(1);
    a.set_y(2);
}

let view: ArrayView<_> = v.as_view();
let a = view.at(0);
assert_eq!(a.x(), 1);
assert_eq!(a.y(), 2);

Methods

impl<'a, T> ArrayView<'a, T> where
    T: for<'b> Struct<'b>, 
[src]

pub fn new(data: &'a [u8]) -> Self
[src]

Creates a new ArrayView to the data at the given address.

The returned array view does not own the data.

pub fn len(&self) -> usize
[src]

Number of elements in the array.

pub fn is_empty(&self) -> bool
[src]

Return true if the array is empty.

pub fn at(&self, index: usize) -> <T as Struct<'a>>::Item
[src]

Returns a read-only handle to the element in the array at position index.

Panics

Panics if index is greater than or equal to ArrayView::len().

pub fn slice<R: RangeBounds<usize>>(&self, range: R) -> Self
[src]

Slice this array view by a given range.

Panics

Panics if the range is outside of bounds of array view.

pub fn iter(&self) -> ArrayViewIter<'a, T>
[src]

Returns an iterator to the elements of the array.

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

Returns a raw bytes representation of the underlying array data.

Trait Implementations

impl<'a, T> AsRef<[u8]> for ArrayView<'a, T> where
    T: for<'b> Struct<'b>, 
[src]

impl<'a, T: Clone> Clone for ArrayView<'a, T> where
    T: for<'b> Struct<'b>, 
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'a, T> Debug for ArrayView<'a, T> where
    T: for<'b> Struct<'b>, 
[src]

Auto Trait Implementations

impl<'a, T> Send for ArrayView<'a, T> where
    T: Send

impl<'a, T> Sync for ArrayView<'a, T> where
    T: Sync

Blanket Implementations

impl<T> From for T
[src]

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

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

type Owned = T

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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