pub enum ArrayView {
F32(&'static [f32]),
F64(&'static [f64]),
I32(&'static [i32]),
I64(&'static [i64]),
U8(&'static [u8]),
}Expand description
View into typed array data - wraps borrowed slices (no copies!)
§Diseño
Para evitar to_vec() completamente, ArrayView contiene referencias con lifetime ’static (seguro porque el caller garantiza que los datos viven mientras el view existe - via Box en C API).
§Uso en FFI
ⓘ
// C tiene: float* data_a, float* data_b (10000 elementos cada uno)
// Crear views (sin to_vec! - solo crea slice):
let view_a = unsafe { ArrayView::from_ptr_f32(data_a, 10000) };
let view_b = unsafe { ArrayView::from_ptr_f32(data_b, 10000) };
// Múltiples operaciones - todas zero-copy:
ops_inplace::elementwise_view(&view_a, &view_b, out, Add)?; // ~23μs
ops_inplace::elementwise_view(&view_a, &view_b, out, Mul)?; // ~23μs
ops_inplace::elementwise_view(&view_a, &view_b, out, Sub)?; // ~23μs
// Sin to_vec(), cada operación corre a velocidad nativa!Variants§
Implementations§
Source§impl ArrayView
impl ArrayView
Sourcepub fn from_slice_f32(data: &[f32]) -> Self
pub fn from_slice_f32(data: &[f32]) -> Self
Create from f32 slice (zero-copy via raw pointer)
§Safety
Caller must ensure data outlives the ArrayView. For FFI, this is safe because ArrayView is boxed and C API controls lifetime.
Sourcepub fn from_slice_f64(data: &[f64]) -> Self
pub fn from_slice_f64(data: &[f64]) -> Self
Create from f64 slice (zero-copy via raw pointer)
Sourcepub fn from_slice_i32(data: &[i32]) -> Self
pub fn from_slice_i32(data: &[i32]) -> Self
Create from i32 slice (zero-copy via raw pointer)
Sourcepub unsafe fn from_ptr_f32(ptr: *const f32, len: usize) -> Self
pub unsafe fn from_ptr_f32(ptr: *const f32, len: usize) -> Self
Create from raw pointer (unsafe - for FFI)
§Safety
ptrmust be valid forlenelements- Data must outlive the ArrayView (caller’s responsibility in C API via Box)
- ’static lifetime is safe because C API holds Box
until destroy()
Sourcepub unsafe fn from_ptr_f64(ptr: *const f64, len: usize) -> Self
pub unsafe fn from_ptr_f64(ptr: *const f64, len: usize) -> Self
Create from raw pointer (unsafe - for FFI)
Sourcepub unsafe fn from_ptr_i32(ptr: *const i32, len: usize) -> Self
pub unsafe fn from_ptr_i32(ptr: *const i32, len: usize) -> Self
Create from raw pointer (unsafe - for FFI)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ArrayView
impl RefUnwindSafe for ArrayView
impl Send for ArrayView
impl Sync for ArrayView
impl Unpin for ArrayView
impl UnwindSafe for ArrayView
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more