PrimitiveArray

Trait PrimitiveArray 

Source
pub trait PrimitiveArray<T>: Sized + ReferenceType
where T: Clone + Default,
{ // Required methods fn new<'env>(env: Env<'env>, size: usize) -> Local<'env, Self>; fn len(self: &Ref<'_, Self>) -> usize; fn get_region(self: &Ref<'_, Self>, start: usize, elements: &mut [T]); fn set_region(self: &Ref<'_, Self>, start: usize, elements: &[T]); // Provided methods fn is_empty(self: &Ref<'_, Self>) -> bool { ... } fn new_from<'env>(env: Env<'env>, elements: &[T]) -> Local<'env, Self> { ... } fn get_region_as_vec( self: &Ref<'_, Self>, range: impl RangeBounds<usize>, ) -> Vec<T> { ... } fn as_vec(self: &Ref<'_, Self>) -> Vec<T> { ... } }
Expand description

A Java Array of some POD-like type such as bool, jbyte, jchar, jshort, jint, jlong, jfloat, or jdouble.

Thread safety of avoiding race conditions is not guaranteed. JNI GetPrimitiveArrayCritical cannot ensure exclusive access to the array, so it is not used here.

See also ObjectArray for arrays of reference types.

Required Methods§

Source

fn new<'env>(env: Env<'env>, size: usize) -> Local<'env, Self>

Uses JNI New{Type}Array to create a new Java array containing “size” elements.

Source

fn len(self: &Ref<'_, Self>) -> usize

Uses JNI GetArrayLength to get the length of the Java array.

Source

fn get_region(self: &Ref<'_, Self>, start: usize, elements: &mut [T])

Uses JNI Get{Type}ArrayRegion to read the contents of the Java array within [start .. start + elements.len()].

Panics if the index is out of bound.

Source

fn set_region(self: &Ref<'_, Self>, start: usize, elements: &[T])

Uses JNI Set{Type}ArrayRegion to set the contents of the Java array within [start .. start + elements.len()].

Panics if the index is out of bound.

Provided Methods§

Source

fn is_empty(self: &Ref<'_, Self>) -> bool

Uses JNI GetArrayLength to get the length of the Java array, returns true if it is 0.

Source

fn new_from<'env>(env: Env<'env>, elements: &[T]) -> Local<'env, Self>

Uses JNI New{Type}Array + Set{Type}ArrayRegion to create a new Java array containing a copy of “elements”.

Source

fn get_region_as_vec( self: &Ref<'_, Self>, range: impl RangeBounds<usize>, ) -> Vec<T>

Uses JNI GetArrayLength + Get{Type}ArrayRegion to read the contents of the Java array within given range into a new Vec.

Panics if the index is out of bound.

Source

fn as_vec(self: &Ref<'_, Self>) -> Vec<T>

Uses JNI GetArrayLength + Get{Type}ArrayRegion to read the contents of the entire Java array into a new Vec.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§