#[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: 'static> ExternalPtr<T>
impl<T: 'static> 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: 'static> AsMut<T> for ExternalPtr<T>
impl<T: 'static> AsMut<T> for ExternalPtr<T>
Source§impl<T: 'static> AsRef<T> for ExternalPtr<T>
impl<T: 'static> 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 + 'static> Debug for ExternalPtr<T>
impl<T: Debug + 'static> Debug for ExternalPtr<T>
Source§impl<T: 'static> Deref for ExternalPtr<T>
impl<T: 'static> Deref for ExternalPtr<T>
Source§impl<T: 'static> DerefMut for ExternalPtr<T>
impl<T: 'static> 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: 'static> TryFrom<&Robj> for &ExternalPtr<T>
impl<T: 'static> TryFrom<&Robj> for &ExternalPtr<T>
Source§impl<T: 'static> TryFrom<&Robj> for ExternalPtr<T>
impl<T: 'static> TryFrom<&Robj> for ExternalPtr<T>
Source§impl<T: 'static> TryFrom<&mut Robj> for &mut ExternalPtr<T>
impl<T: 'static> TryFrom<&mut Robj> for &mut ExternalPtr<T>
Source§impl<T: 'static> TryFrom<Robj> for &ExternalPtr<T>
impl<T: 'static> TryFrom<Robj> for &ExternalPtr<T>
Source§impl<T: 'static> TryFrom<Robj> for &mut ExternalPtr<T>
impl<T: 'static> TryFrom<Robj> for &mut ExternalPtr<T>
Source§impl<T: 'static> TryFrom<Robj> for ExternalPtr<T>
impl<T: 'static> 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