Struct extendr_api::wrapper::externalptr::ExternalPtr
source · #[repr(transparent)]pub struct ExternalPtr<T> {
pub(crate) robj: Robj,
_marker: PhantomData<T>,
}
Expand description
Wrapper for creating R objects containing any Rust object.
use extendr_api::prelude::*;
test! {
let extptr = ExternalPtr::new(1);
assert_eq!(*extptr, 1);
let robj : Robj = extptr.into();
let extptr2 : ExternalPtr<i32> = robj.try_into().unwrap();
assert_eq!(*extptr2, 1);
}
Fields§
§robj: Robj
This is the contained Robj.
_marker: PhantomData<T>
This is a zero-length object that holds the type of the object.
Implementations§
source§impl<T> ExternalPtr<T>
impl<T> ExternalPtr<T>
sourcepub fn new(val: T) -> Self
pub fn new(val: T) -> Self
Construct an external pointer object from any type T. In this case, the R object owns the data and will drop the Rust object when the last reference is removed via register_c_finalizer.
An ExternalPtr behaves like a Box except that the information is tracked by a R object.
sourcepub fn tag(&self) -> Robj
pub fn tag(&self) -> Robj
Get the “tag” of an external pointer. This is the type name in the common case.
sourcepub fn protected(&self) -> Robj
pub fn protected(&self) -> Robj
Get the “protected” field of an external pointer. This is NULL in the common case.
sourcepub fn addr(&self) -> &T
pub fn addr(&self) -> &T
Get the “address” field of an external pointer. Normally, we will use Deref to do this.
§Panics
When the underlying pointer is C NULL
.
sourcepub fn addr_mut(&mut self) -> &mut T
pub fn addr_mut(&mut self) -> &mut T
Get the “address” field of an external pointer as a mutable reference. Normally, we will use DerefMut to do this.
§Panics
When the underlying pointer is C NULL
.
sourcepub fn try_addr(&self) -> Result<&T>
pub fn try_addr(&self) -> Result<&T>
Get the “address” field of an external pointer. Normally, we will use Deref to do this.
§Panics
When the underlying pointer is C NULL
.
sourcepub fn try_addr_mut(&mut self) -> Result<&mut T>
pub fn try_addr_mut(&mut self) -> Result<&mut T>
Get the “address” field of an external pointer as a mutable reference. Normally, we will use DerefMut to do this.
§Panics
When the underlying pointer is C NULL
.
Trait Implementations§
source§impl<T> AsMut<T> for ExternalPtr<T>
impl<T> AsMut<T> for ExternalPtr<T>
source§impl<T> AsRef<T> for ExternalPtr<T>
impl<T> AsRef<T> for ExternalPtr<T>
source§impl<T> Attributes for ExternalPtr<T>
impl<T> Attributes for ExternalPtr<T>
set_attrib
source§fn get_attrib<'a, N>(&self, name: N) -> Option<Robj>
fn get_attrib<'a, N>(&self, name: N) -> Option<Robj>
Robj
if it exists. Read moresource§fn has_attrib<'a, N>(&self, name: N) -> bool
fn has_attrib<'a, N>(&self, name: N) -> bool
source§fn set_attrib<N, V>(&mut self, name: N, value: V) -> Result<&mut Self>
fn set_attrib<N, V>(&mut self, name: N, value: V) -> Result<&mut Self>
source§fn names(&self) -> Option<StrIter>
fn names(&self) -> Option<StrIter>
names
attribute as a string iterator if one exists. Read moresource§fn set_names<T>(&mut self, names: T) -> Result<&mut Self>
fn set_names<T>(&mut self, names: T) -> Result<&mut Self>
names
attribute from a string iterator. Read moresource§fn dim(&self) -> Option<Integers>
fn dim(&self) -> Option<Integers>
dim
attribute as an integer iterator if one exists. Read moresource§fn dimnames(&self) -> Option<ListIter>
fn dimnames(&self) -> Option<ListIter>
dimnames
attribute as a list iterator if one exists. Read moresource§fn class(&self) -> Option<StrIter>
fn class(&self) -> Option<StrIter>
class
attribute as a string iterator if one exists. Read moresource§fn set_class<T>(&mut self, class: T) -> Result<&mut Self>
fn set_class<T>(&mut self, class: T) -> Result<&mut Self>
class
attribute from a string iterator, and return the same
object. Read moresource§impl<T> Clone for ExternalPtr<T>
impl<T> Clone for ExternalPtr<T>
Manual implementation of Clone
trait, because the assumed constraint T: Clone
is not necessary.
source§impl<T> Conversions for ExternalPtr<T>
impl<T> Conversions for ExternalPtr<T>
as_*()
source§fn as_language(&self) -> Option<Language>
fn as_language(&self) -> Option<Language>
source§fn as_pairlist(&self) -> Option<Pairlist>
fn as_pairlist(&self) -> Option<Pairlist>
source§fn as_expressions(&self) -> Option<Expressions>
fn as_expressions(&self) -> Option<Expressions>
source§fn as_environment(&self) -> Option<Environment>
fn as_environment(&self) -> Option<Environment>
source§fn as_function(&self) -> Option<Function>
fn as_function(&self) -> Option<Function>
source§fn as_promise(&self) -> Option<Promise>
fn as_promise(&self) -> Option<Promise>
source§impl<T: Debug> Debug for ExternalPtr<T>
impl<T: Debug> Debug for ExternalPtr<T>
source§impl<T> Deref for ExternalPtr<T>
impl<T> Deref for ExternalPtr<T>
source§impl<T> DerefMut for ExternalPtr<T>
impl<T> DerefMut for ExternalPtr<T>
source§impl<T> From<ExternalPtr<T>> for Robj
impl<T> From<ExternalPtr<T>> for Robj
source§fn from(val: ExternalPtr<T>) -> Self
fn from(val: ExternalPtr<T>) -> Self
source§impl<T> GetSexp for ExternalPtr<T>
impl<T> GetSexp for ExternalPtr<T>
source§impl<T> Length for ExternalPtr<T>
impl<T> Length for ExternalPtr<T>
len() and is_empty()
source§impl<T> Operators for ExternalPtr<T>
impl<T> Operators for ExternalPtr<T>
dollar() etc.
source§impl<T> PartialEq for ExternalPtr<T>
impl<T> PartialEq for ExternalPtr<T>
Manual implementation of PartialEq
, because the constraint T: PartialEq
is not necessary.
source§impl<T> Rinternals for ExternalPtr<T>
impl<T> Rinternals for ExternalPtr<T>
find_var() etc.
source§fn is_logical(&self) -> bool
fn is_logical(&self) -> bool
source§fn is_complex(&self) -> bool
fn is_complex(&self) -> bool
source§fn is_expressions(&self) -> bool
fn is_expressions(&self) -> bool
source§fn is_environment(&self) -> bool
fn is_environment(&self) -> bool
source§fn is_promise(&self) -> bool
fn is_promise(&self) -> bool
source§fn is_external_pointer(&self) -> bool
fn is_external_pointer(&self) -> bool
source§fn get_current_srcref(val: i32) -> Robj
fn get_current_srcref(val: i32) -> Robj
source§fn get_src_filename(&self) -> Robj
fn get_src_filename(&self) -> Robj
source§fn as_character_vector(&self) -> Robj
fn as_character_vector(&self) -> Robj
source§fn coerce_vector(&self, sexptype: SEXPTYPE) -> Robj
fn coerce_vector(&self, sexptype: SEXPTYPE) -> Robj
source§fn pair_to_vector_list(&self) -> Robj
fn pair_to_vector_list(&self) -> Robj
source§fn vector_to_pair_list(&self) -> Robj
fn vector_to_pair_list(&self) -> Robj
source§fn as_character_factor(&self) -> Robj
fn as_character_factor(&self) -> Robj
source§fn duplicate(&self) -> Robj
fn duplicate(&self) -> Robj
source§fn find_function<K: TryInto<Symbol, Error = Error>>(
&self,
key: K,
) -> Result<Robj>
fn find_function<K: TryInto<Symbol, Error = Error>>( &self, key: K, ) -> Result<Robj>
source§fn find_var<K: TryInto<Symbol, Error = Error>>(&self, key: K) -> Result<Robj>
fn find_var<K: TryInto<Symbol, Error = Error>>(&self, key: K) -> Result<Robj>
source§fn xlengthgets(&self, new_len: usize) -> Result<Robj>
fn xlengthgets(&self, new_len: usize) -> Result<Robj>
source§fn alloc_vector(sexptype: SEXPTYPE, len: usize) -> Robj
fn alloc_vector(sexptype: SEXPTYPE, len: usize) -> Robj
source§fn is_function(&self) -> bool
fn is_function(&self) -> bool
source§fn is_integer(&self) -> bool
fn is_integer(&self) -> bool
source§fn is_language(&self) -> bool
fn is_language(&self) -> bool
source§fn is_pairlist(&self) -> bool
fn is_pairlist(&self) -> bool
source§fn is_number(&self) -> bool
fn is_number(&self) -> bool
source§fn is_primitive(&self) -> bool
fn is_primitive(&self) -> bool
source§fn is_user_binop(&self) -> bool
fn is_user_binop(&self) -> bool
source§fn is_vector_atomic(&self) -> bool
fn is_vector_atomic(&self) -> bool
source§fn is_vector_list(&self) -> bool
fn is_vector_list(&self) -> bool
source§fn is_vectorizable(&self) -> bool
fn is_vectorizable(&self) -> bool
fn is_missing_arg(&self) -> bool
fn is_unbound_value(&self) -> bool
fn is_package_env(&self) -> bool
fn package_env_name(&self) -> Robj
fn is_namespace_env(&self) -> bool
fn namespace_env_spec(&self) -> Robj
source§fn is_altinteger(&self) -> bool
fn is_altinteger(&self) -> bool
true
if this is an integer ALTREP object.source§fn is_altreal(&self) -> bool
fn is_altreal(&self) -> bool
true
if this is an real ALTREP object.source§fn is_altlogical(&self) -> bool
fn is_altlogical(&self) -> bool
true
if this is an logical ALTREP object.source§fn is_altstring(&self) -> bool
fn is_altstring(&self) -> bool
true
if this is an integer ALTREP object.source§fn is_altlist(&self) -> bool
fn is_altlist(&self) -> bool
true
if this is an integer ALTREP object.source§impl<T> Slices for ExternalPtr<T>
impl<T> Slices for ExternalPtr<T>
as_typed_slice_raw() etc.
source§unsafe fn as_typed_slice_raw<T>(&self) -> &[T]
unsafe fn as_typed_slice_raw<T>(&self) -> &[T]
source§unsafe fn as_typed_slice_raw_mut<T>(&mut self) -> &mut [T]
unsafe fn as_typed_slice_raw_mut<T>(&mut self) -> &mut [T]
source§impl<T> TryFrom<&Robj> for &ExternalPtr<T>
impl<T> TryFrom<&Robj> for &ExternalPtr<T>
source§impl<T> TryFrom<&Robj> for ExternalPtr<T>
impl<T> TryFrom<&Robj> for ExternalPtr<T>
source§impl<T> TryFrom<&mut Robj> for &mut ExternalPtr<T>
impl<T> TryFrom<&mut Robj> for &mut ExternalPtr<T>
source§impl<T> TryFrom<Robj> for ExternalPtr<T>
impl<T> TryFrom<Robj> for ExternalPtr<T>
Auto Trait Implementations§
impl<T> Freeze for ExternalPtr<T>
impl<T> RefUnwindSafe for ExternalPtr<T>where
T: RefUnwindSafe,
impl<T> !Send for ExternalPtr<T>
impl<T> !Sync for ExternalPtr<T>
impl<T> Unpin for ExternalPtr<T>where
T: Unpin,
impl<T> UnwindSafe for ExternalPtr<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<'short, T, Target> AsGeneralizedMut<'short, &'short mut Target> for T
impl<'short, T, Target> AsGeneralizedMut<'short, &'short mut Target> for T
fn as_generalized_mut(&'short mut self) -> &'short mut Target
§impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
fn as_generalized_ref(&'short self) -> &'short Target
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more