Trait AltInteger

Source
pub trait AltInteger: 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) -> i32;

    // Provided methods
    fn copy_to(&mut self, new: &mut [i32], offset: usize) { ... }
    fn sum(&mut self, na_rm: bool) -> Option<f64> { ... }
    fn min(&mut self, na_rm: bool) -> Option<f64> { ... }
    fn max(&mut self, na_rm: bool) -> Option<f64> { ... }
    fn inspect(&mut self, is_materialized: bool) { ... }
    fn into_altrep(self) -> Result<Sexp> { ... }
    fn try_from_altrep_ref(x: &IntegerSexp) -> Result<&Self> { ... }
    fn try_from_altrep_mut(
        x: &mut IntegerSexp,
        invalidate_cache: bool,
    ) -> Result<&mut Self> { ... }
    fn try_from_altrep(x: IntegerSexp) -> 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) -> i32

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 [i32], 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 sum(&mut self, na_rm: bool) -> Option<f64>

Return the sum of all values.

This returns f64 because the sum of i32 might be beyond the range of i32.

Source

fn min(&mut self, na_rm: bool) -> Option<f64>

Return the minimum value.

This returns f64 because min() of an empty vector is Inf. Note that it’s this function’s responsibility to handle such cases:

  • min(integer(0L))
  • min(c(NA_integer_), na.rm = TRUE)
Source

fn max(&mut self, na_rm: bool) -> Option<f64>

Return the maximum value.

This returns f64 because max() of an empty vector is -Inf. Note that it’s this function’s responsibility to handle such cases:

  • max(integer(0L))
  • max(c(NA_integer_), na.rm = TRUE)
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: &IntegerSexp) -> Result<&Self>

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

Source

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

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

Source

fn try_from_altrep(x: IntegerSexp) -> 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§