savvy::altrep

Trait AltReal

Source
pub trait AltReal: Sized + IntoExtPtrSexp {
    const CLASS_NAME: &'static str;
    const PACKAGE_NAME: &'static str;

    // Required methods
    fn length(&mut self) -> usize;
    fn elt(&mut self, i: usize) -> f64;

    // Provided methods
    fn copy_to(&mut self, new: &mut [f64], offset: usize) { ... }
    fn inspect(&mut self, is_materialized: bool) { ... }
    fn into_altrep(self) -> Result<Sexp> { ... }
    fn try_from_altrep_ref(x: &RealSexp) -> Result<&Self> { ... }
    fn try_from_altrep_mut(
        x: &mut RealSexp,
        invalidate_cache: bool,
    ) -> Result<&mut Self> { ... }
    fn try_from_altrep(x: RealSexp) -> Result<Self> { ... }
}

Required Associated Constants§

Source

const CLASS_NAME: &'static str

Class name to identify the ALTREP class.

Source

const PACKAGE_NAME: &'static str

Package name to identify the ALTREP class.

Required Methods§

Source

fn length(&mut self) -> usize

Returns the length of the data.

Source

fn elt(&mut self, i: usize) -> f64

Returns the value of i-th element. Note that, it seems R handles the out-of-bound check, so you don’t need to implement it here.

Provided Methods§

Source

fn copy_to(&mut self, new: &mut [f64], offset: usize)

Copies the specified range of the data into a new memory. This is used when the ALTREP needs to be materialized.

For example, you can use copy_from_slice() for more efficient copying of the values.

Source

fn inspect(&mut self, is_materialized: bool)

What gets printed when .Internal(inspect(x)) is used.

Source

fn into_altrep(self) -> Result<Sexp>

Converts the struct into an ALTREP object.

Source

fn try_from_altrep_ref(x: &RealSexp) -> Result<&Self>

Extracts the reference (&T) of the underlying data.

Source

fn try_from_altrep_mut( x: &mut RealSexp, invalidate_cache: bool, ) -> Result<&mut Self>

Extracts the mutable reference (&mut T) of the underlying data.

Source

fn try_from_altrep(x: RealSexp) -> Result<Self>

Takes the underlying data. After this operation, the external pointer is replaced with a null pointer.

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§