Struct jlrs::value::array::Array [−][src]
#[repr(transparent)]pub struct Array<'frame, 'data>(_, _, _);
An n-dimensional Julia array. This struct implements JuliaTypecheck
and Cast
. It can
be used in combination with DataType::is
and Value::is
; if the check returns true
the Value
can be cast to Array
:
julia.scope(|_global, frame| { let arr = Value::new_array::<f64, _, _, _>(&mut *frame, (3, 3))?; assert!(arr.is::<Array>()); assert!(arr.cast::<Array>().is_ok()); Ok(()) }).unwrap();
Each element in the backing storage is either stored as a Value
or inline. You can check
how the data is stored by calling Array::is_value_array
or Array::is_inline_array
.
Note that this is not necessarily consistent across different versions of Julia; the array
might be value array in Julia 1.0, but an inline array in Julia 1.5. If you want to ensure the
data is not stored inline, you should use a mutable struct as the element type. If the data is
stored inline, you will need to provide a type with the appropriate layout, the easiest way to
create these for types that are not available in jlrs is to use JlrsReflect.jl
.
Arrays that contain integers or floats are an example of inline arrays. Their data is stored
as an array that contains numbers of the appropriate type, for example an array of Float32
s
in Julia is backed by an an array of f32
s. The data of these arrays can be accessed with
Array::inline_data
and Array::inline_data_mut
, and copied from Julia to Rust with
Array::copy_inline_data
. In order to call these methods the type of the elements must be
provided, arrays that contain numbers can be accessed by providing the appropriate Rust type
(eg f32
for Float32
and u64
for UInt64
).
If the data isn’t inlined each element is stored as a Value
. This data can be accessed
using Array::value_data
and Array::value_data_mut
but this is unsafe.
Implementations
impl<'frame, 'data> Array<'frame, 'data>
[src]
impl<'frame, 'data> Array<'frame, 'data>
[src]pub fn into_typed_array<T>(self) -> JlrsResult<TypedArray<'frame, 'data, T>> where
T: Copy + ValidLayout,
[src]
T: Copy + ValidLayout,
Convert this untyped array into a TypedArray
.
pub fn dimensions(self) -> Dimensions
[src]
Returns the array’s dimensions.
pub fn element_type(self) -> Value<'frame, 'static>
[src]
Returns the type of this array’s elements.
pub fn contains<T: ValidLayout>(self) -> bool
[src]
Returns true
if the type of the elements of this array is T
.
pub fn contains_inline<T: ValidLayout>(self) -> bool
[src]
Returns true
if the type of the elements of this array is T
and these elements are
stored inline.
pub fn is_inline_array(self) -> bool
[src]
Returns true if the elements of the array are stored inline.
pub fn has_inlined_pointers(self) -> bool
[src]
Returns true if the elements of the array are stored inline and at least one of the field of the inlined type is a pointer.
pub fn is_value_array(self) -> bool
[src]
Returns true if the elements of the array are stored as Value
s.
pub fn copy_inline_data<T>(self) -> JlrsResult<CopiedArray<T>> where
T: ValidLayout,
[src]
T: ValidLayout,
Copy the data of an inline array to Rust. Returns JlrsError::NotInline
if the data is
not stored inline or JlrsError::WrongType
if the type of the elements is incorrect.
pub fn inline_data<'borrow, 'fr, T, F>(
self,
frame: &'borrow F
) -> JlrsResult<ArrayData<'borrow, 'fr, T, F>> where
T: ValidLayout,
F: Frame<'fr>,
[src]
self,
frame: &'borrow F
) -> JlrsResult<ArrayData<'borrow, 'fr, T, F>> where
T: ValidLayout,
F: Frame<'fr>,
Immutably borrow inline array data, you can borrow data from multiple arrays at the same
time. Returns JlrsError::NotInline
if the data is not stored inline or
JlrsError::WrongType
if the type of the elements is incorrect.
pub fn inline_data_mut<'borrow, 'fr, T, F>(
self,
frame: &'borrow mut F
) -> JlrsResult<InlineArrayDataMut<'borrow, 'fr, T, F>> where
T: ValidLayout,
F: Frame<'fr>,
[src]
self,
frame: &'borrow mut F
) -> JlrsResult<InlineArrayDataMut<'borrow, 'fr, T, F>> where
T: ValidLayout,
F: Frame<'fr>,
Mutably borrow inline array data, you can mutably borrow a single array at the same time.
Returns JlrsError::NotInline
if the data is not stored inline or JlrsError::WrongType
if the type of the elements is incorrect.
pub unsafe fn unrestricted_inline_data_mut<'borrow, 'fr, T, F>(
self,
frame: &'borrow F
) -> JlrsResult<UnrestrictedInlineArrayDataMut<'borrow, 'fr, T, F>> where
T: ValidLayout,
F: Frame<'fr>,
[src]
self,
frame: &'borrow F
) -> JlrsResult<UnrestrictedInlineArrayDataMut<'borrow, 'fr, T, F>> where
T: ValidLayout,
F: Frame<'fr>,
Mutably borrow inline array data without the restriction that only a single array can be mutably borrowed. It’s your responsibility to ensure you don’t create multiple mutable references to the same array data.
Returns JlrsError::NotInline
if the data is not stored inline or JlrsError::WrongType
if the type of the elements is incorrect.
pub unsafe fn value_data<'borrow, 'fr, F>(
self,
frame: &'borrow F
) -> JlrsResult<ArrayData<'borrow, 'fr, Value<'frame, 'data>, F>> where
F: Frame<'fr>,
[src]
self,
frame: &'borrow F
) -> JlrsResult<ArrayData<'borrow, 'fr, Value<'frame, 'data>, F>> where
F: Frame<'fr>,
Immutably borrow the data of this value array, you can borrow data from multiple arrays at
the same time. The values themselves can be mutable, but you can’t replace an element with
another value. Returns JlrsError::Inline
if the data is stored inline.
Safety: no slot on the GC stack is required to access and use the values in this array,
the GC is aware of the array’s data. If the element is changed either from Rust or Julia,
the original value is no longer protected from garbage collection. If you need to keep
using this value you must protect it by calling Value::reroot
.
pub unsafe fn value_data_mut<'borrow, 'fr, F>(
self,
frame: &'borrow mut F
) -> JlrsResult<ValueArrayDataMut<'borrow, 'frame, 'data, 'fr, F>> where
F: Frame<'fr>,
[src]
self,
frame: &'borrow mut F
) -> JlrsResult<ValueArrayDataMut<'borrow, 'frame, 'data, 'fr, F>> where
F: Frame<'fr>,
Mutably borrow the data of this value array, you can mutably borrow a single array at the
same time. Returns JlrsError::Inline
if the data is stored inline.
Safety: no slot on the GC stack is required to access and use the values in this array,
the GC is aware of the array’s data. If the element is changed either from Rust or Julia,
the original value is no longer protected from garbage collection. If you need to keep
using this value you must protect it by calling Value::reroot
.
pub unsafe fn unrestricted_value_data_mut<'borrow, 'fr, F>(
self,
frame: &'borrow F
) -> JlrsResult<UnrestrictedValueArrayDataMut<'borrow, 'frame, 'data, 'fr, F>> where
F: Frame<'fr>,
[src]
self,
frame: &'borrow F
) -> JlrsResult<UnrestrictedValueArrayDataMut<'borrow, 'frame, 'data, 'fr, F>> where
F: Frame<'fr>,
Mutably borrow the data of this value array without the restriction that only a single
array can be mutably borrowed. It’s your responsibility to ensure you don’t create
multiple mutable references to the same array data. Returns JlrsError::Inline
if the
data is stored inline.
Safety: no slot on the GC stack is required to access and use the values in this array,
the GC is aware of the array’s data. If the element is changed either from Rust or Julia,
the original value is no longer protected from garbage collection. If you need to keep
using this value you must protect it by calling Value::reroot
.
pub fn as_value(self) -> Value<'frame, 'data>
[src]
Convert self
to a Value
.
Trait Implementations
impl<'frame, 'data> Cast<'frame, 'data> for Array<'frame, 'data>
[src]
impl<'frame, 'data> Cast<'frame, 'data> for Array<'frame, 'data>
[src]type Output = Self
fn cast(value: Value<'frame, 'data>) -> JlrsResult<Self::Output>
[src]
unsafe fn cast_unchecked(value: Value<'frame, 'data>) -> Self::Output
[src]
impl<'frame, 'data, T: Copy + ValidLayout> Into<Array<'frame, 'data>> for TypedArray<'frame, 'data, T>
[src]
impl<'frame, 'data, T: Copy + ValidLayout> Into<Array<'frame, 'data>> for TypedArray<'frame, 'data, T>
[src]impl<'frame, 'data> JuliaTypecheck for Array<'frame, 'data>
[src]
impl<'frame, 'data> JuliaTypecheck for Array<'frame, 'data>
[src]unsafe fn julia_typecheck(t: DataType<'_>) -> bool
[src]
impl<'frame: 'borrow, 'data: 'borrow, 'borrow, T: ValidLayout + Copy> NdArray<'borrow, T> for Array<'frame, 'data>
[src]
impl<'frame: 'borrow, 'data: 'borrow, 'borrow, T: ValidLayout + Copy> NdArray<'borrow, T> for Array<'frame, 'data>
[src]fn array_view<'fr: 'borrow, F>(
self,
frame: &'borrow F
) -> JlrsResult<ArrayView<'borrow, T, Dim<IxDynImpl>>> where
F: Frame<'fr>,
T: ValidLayout + Copy,
[src]
self,
frame: &'borrow F
) -> JlrsResult<ArrayView<'borrow, T, Dim<IxDynImpl>>> where
F: Frame<'fr>,
T: ValidLayout + Copy,
fn array_view_mut<'fr: 'borrow, F>(
self,
frame: &'borrow mut F
) -> JlrsResult<ArrayViewMut<'borrow, T, Dim<IxDynImpl>>> where
F: Frame<'fr>,
T: ValidLayout + Copy,
[src]
self,
frame: &'borrow mut F
) -> JlrsResult<ArrayViewMut<'borrow, T, Dim<IxDynImpl>>> where
F: Frame<'fr>,
T: ValidLayout + Copy,
impl<'frame, 'data> ValidLayout for Array<'frame, 'data>
[src]
impl<'frame, 'data> ValidLayout for Array<'frame, 'data>
[src]unsafe fn valid_layout(v: Value<'_, '_>) -> bool
[src]
Auto Trait Implementations
impl<'frame, 'data> RefUnwindSafe for Array<'frame, 'data>
impl<'frame, 'data> RefUnwindSafe for Array<'frame, 'data>
impl<'frame, 'data> UnwindSafe for Array<'frame, 'data>
impl<'frame, 'data> UnwindSafe for Array<'frame, 'data>