Type Definition ndarray::RawArrayView [−][src]
pub type RawArrayView<A, D> = ArrayBase<RawViewRepr<*const A>, D>;
Expand description
A read-only array view without a lifetime.
This is similar to ArrayView
but does not carry any lifetime or
ownership information, and its data cannot be read without an unsafe
conversion into an ArrayView
. The relationship between RawArrayView
and ArrayView
is somewhat analogous to the relationship between *const T
and &T
, but RawArrayView
has additional requirements that *const T
does not, such as non-nullness.
The RawArrayView<A, D>
is parameterized by A
for the element type and
D
for the dimensionality.
Raw array views have all the methods of an array (see
ArrayBase
).
See also RawArrayViewMut
.
Warning
You can’t use this type wih an arbitrary raw pointer; see
from_shape_ptr
for details.
Implementations
pub unsafe fn from_shape_ptr<Sh>(shape: Sh, ptr: *const A) -> Self where
Sh: Into<StrideShape<D>>,
pub unsafe fn from_shape_ptr<Sh>(shape: Sh, ptr: *const A) -> Self where
Sh: Into<StrideShape<D>>,
Create an RawArrayView<A, D>
from shape information and a raw pointer
to the elements.
Safety
The caller is responsible for ensuring all of the following:
-
ptr
must be non-null, and it must be safe to.offset()
ptr
by zero. -
It must be safe to
.offset()
the pointer repeatedly along all axes and calculate thecount
s for the.offset()
calls without overflow, even if the array is empty or the elements are zero-sized.In other words,
-
All possible pointers generated by moving along all axes must be in bounds or one byte past the end of a single allocation with element type
A
. The only exceptions are if the array is empty or the element type is zero-sized. In these cases,ptr
may be dangling, but it must still be safe to.offset()
the pointer along the axes. -
The offset in units of bytes between the least address and greatest address by moving along all axes must not exceed
isize::MAX
. This constraint prevents the computed offset, in bytes, from overflowingisize
regardless of the starting point due to past offsets. -
The offset in units of
A
between the least address and greatest address by moving along all axes must not exceedisize::MAX
. This constraint prevents overflow when calculating thecount
parameter to.offset()
regardless of the starting point due to past offsets.
-
-
The product of non-zero axis lengths must not exceed
isize::MAX
.
Converts to a read-only view of the array.
Safety
From a safety standpoint, this is equivalent to dereferencing a raw pointer for every element in the array. You must ensure that all of the data is valid, ensure that the pointer is aligned, and choose the correct lifetime.
Split the array view along axis
and return one array pointer strictly
before the split and one array pointer after the split.
Panics if axis
or index
is out of bounds.
Cast the raw pointer of the raw array view to a different type
Panics if element size is not compatible.
Lack of panic does not imply it is a valid cast. The cast works the same way as regular raw pointer casts.
While this method is safe, for the same reason as regular raw pointer casts are safe, access through the produced raw view is only possible in an unsafe block or function.