Struct npyz::NpyData

source ·
pub struct NpyData<'a, T: Deserialize> { /* private fields */ }
👎Deprecated since 0.5.0: use NpyReader instead
Expand description

Legacy type for reading npy files.

This type provides the same API for reading from npy-rs 0.4.0, to help with migration. It will later be removed in favor of NpyFile.

The data is internally stored as a byte array, and deserialized only on-demand to minimize unnecessary allocations. The whole contents of the file can be deserialized by the NpyData::to_vec method.

Implementations§

source§

impl<'a, T: Deserialize> NpyData<'a, T>

source

pub fn from_bytes(bytes: &'a [u8]) -> Result<NpyData<'a, T>>

Deserialize a NPY file represented as bytes

source

pub fn len(&self) -> usize

Returns the total number of elements.

source

pub fn is_empty(&self) -> bool

Returns whether there are zero records in this NpyData structure.

source

pub fn get(&self, i: usize) -> Option<T>

Gets a single data-record with the specified flat index.

Returns None if the index is out of bounds.

Panics

Panics if the bytes stored for the element are invalid for the dtype.

source

pub fn get_unchecked(&self, i: usize) -> T

Gets a single data-record with the specified index.

Panics

Panics if the bytes stored for the element are invalid for the dtype, or if the index is out of bounds.

source

pub fn to_vec(&self) -> Vec<T>

Construct a vector with the deserialized contents of the whole file.

The output is a flat vector with the elements in the same order that they are in the file. NpyData is deprecated and does not provide any tools for inspecting the shape and layout of the data, so if you want to correctly read multi-dimensional arrays you should switch to NpyFile.

Trait Implementations§

source§

impl<'a, T> IntoIterator for NpyData<'a, T>
where T: Deserialize + 'a,

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a, T> RefUnwindSafe for NpyData<'a, T>

§

impl<'a, T> Send for NpyData<'a, T>
where <T as Deserialize>::TypeReader: Send,

§

impl<'a, T> Sync for NpyData<'a, T>
where <T as Deserialize>::TypeReader: Sync,

§

impl<'a, T> Unpin for NpyData<'a, T>
where <T as Deserialize>::TypeReader: Unpin,

§

impl<'a, T> UnwindSafe for NpyData<'a, T>

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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.