Skip to main content

frombuffer_view

Function frombuffer_view 

Source
pub fn frombuffer_view<'a, T: Element, D: Dimension>(
    dim: D,
    buf: &'a [u8],
) -> FerrayResult<ArrayView<'a, T, D>>
Expand description

Create a zero-copy ArrayView over an existing byte buffer (#364).

Unlike frombuffer, which copies bytes into a freshly allocated Array, this function returns a view whose lifetime is tied to the input slice. This is the equivalent of NumPy’s np.frombuffer() with a memoryview source — the primary building block for zero-copy interop with mmap, shared memory, network buffers, and FFI.

§Errors

  • InvalidValue if T is a ZST.
  • InvalidValue if buf.len() is not a multiple of size_of::<T>().
  • ShapeMismatch if the element count doesn’t match dim.size().
  • InvalidValue if buf.as_ptr() is not aligned to align_of::<T>() (views require proper alignment — use the copying frombuffer instead if alignment cannot be guaranteed).
  • InvalidValue if T is bool and any byte is outside {0x00, 0x01}.