Struct rmin::Owned

source ·
pub struct Owned<T: RType> { /* private fields */ }
Expand description

Owned SEXP, allocated by Rust code.

You could modify object as a slice object, and return it as a R vector. Once it is created, you should take care about calling R function. The ideal way is call R functions before it is allocated (e.g., convert all SEXP<T> into &[T]) then allocate only 1 Owned object.

Implementations§

source§

impl<T: RType> Owned<T>

source

pub fn protect(self) -> Protected<T>

This function provides a way to protect any vector from R’s GC You should take care about that, any allocation might recycle the previous allocated vector In the current fasion, we only alloc 1 return vector, thus protect is not necessary In case you want to communicate with R functions, you must convert all your Owned values to the Protected version.

Examples found in repository?
examples/compare-rmin.rs (line 6)
4
5
6
7
8
9
10
pub extern "C-unwind" fn add_protect(a:SEXP<f64>,b:SEXP<f64>) -> Owned<f64> {
    handle_panic(||{
        let mut c=Owned::new(1).protect();
        c[0]=a[0]+b[0];
        c.into()
    })
}

Trait Implementations§

source§

impl<T: RType> From<Owned<T>> for SEXP<T>

source§

fn from(s: Owned<T>) -> Self

Converts to this type from the input type.
source§

impl<T: RType> Index<usize> for Owned<T>
where Owned<T>: SExt,

§

type Output = <<Owned<T> as SExt>::Data as RType>::Data

The returned type after indexing.
source§

fn index(&self, index: usize) -> &<<Owned<T> as SExt>::Data as RType>::Data

Performs the indexing (container[index]) operation. Read more
source§

impl<T: RTypeMut> IndexMut<usize> for Owned<T>
where Owned<T>: Mutable, <Owned<T> as SExt>::Data: RTypeMut,

source§

fn index_mut( &mut self, index: usize ) -> &mut <<Owned<T> as SExt>::Data as RType>::Data

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T: RType> SExt for Owned<T>

§

type Data = T

SEXP Associated data, normally double->f64, integer->i32, logical->u32, character->u8, Other data might be added in the future.
source§

fn as_sexp(&self) -> *mut SEXPREC

get the inner SEXP.
source§

fn new(len: <Self::Data as RType>::New) -> Self

allocate a new SEXP object with length for u8 (CHARcrate::libR::SEXP), new with length is not allowed thus CHARcrate::libR::SEXP accept a String object.
source§

fn is_correct_type(&self) -> bool

check whether the data has the desired type
source§

fn len(&self) -> usize

get length of this SEXP.
source§

unsafe fn data_unchecked(&self) -> &[<Self::Data as RType>::Data]

got the read-only data of a SEXP object SAFETY: caller should ensure this SEXP has data with Read more
source§

fn data(&self) -> &[<Self::Data as RType>::Data]

got the read-only data of a SEXP object

Auto Trait Implementations§

§

impl<T> Freeze for Owned<T>

§

impl<T> RefUnwindSafe for Owned<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Owned<T>

§

impl<T> !Sync for Owned<T>

§

impl<T> Unpin for Owned<T>
where T: Unpin,

§

impl<T> UnwindSafe for Owned<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.