Skip to main content

ExternalPtrRef

Struct ExternalPtrRef 

Source
pub struct ExternalPtrRef<'a, T: TypedExternal + ?Sized> {
    value: Shared<'a, T>,
    owner: &'a SEXP,
    _main_thread: PhantomData<*mut ()>,
}
Expand description

A shared borrow of a Rust value together with its R object.

ExternalPtr::borrow makes one, and a #[miniextendr] function or method takes one as a parameter (or as self: ExternalPtrRef<'_, Self>) when it needs the R object as well as the value: the sidecar accessors, the object’s identity (ExternalPtrRef::as_sexp). A body that needs only the value takes &T.

The view holds a shared borrow of the value’s RefCell for its whole lifetime: a method of the same object that needs it mutably, a &mut T argument holding it, or ExternalPtr::borrow_mut meanwhile raises the R error of class miniextendr_borrow_conflict. It never owns or consumes the value, can represent ordinary Any storage or erased trait-ABI storage, and cannot cross threads. Pass it on without moving it with rb.

A borrowed handle cannot outlive its owner:

ⓘ
use miniextendr_api::{ExternalPtr, ExternalPtrRef, TypedExternal};
fn escape<T: TypedExternal>(owner: ExternalPtr<T>) -> ExternalPtrRef<'static, T> {
    owner.borrow()
}

Fields§

§value: Shared<'a, T>§owner: &'a SEXP§_main_thread: PhantomData<*mut ()>

Implementations§

Source§

impl<'a, T: TypedExternal + ?Sized> ExternalPtrRef<'a, T>

Source

pub(super) fn from_guard(owner: &'a SEXP, guard: Ref<'a, T>) -> Self

Hold guard, a borrow of the value of the R object owner.

Source

pub fn rb(&self) -> ExternalPtrRef<'_, T>

A shared view of the same value for a shorter lifetime, to pass on without moving this one. The value stays borrowed until this view drops.

Source

pub fn as_sexp(this: &Self) -> SEXP

The R object (EXTPTRSXP) holding the value.

An associated function, ExternalPtrRef::as_sexp(&view), so that it doesn’t hide a method of T of the same name.

Source§

impl<'a, T: TypedExternal> ExternalPtrRef<'a, T>

Source

#[doc(hidden)]
pub unsafe fn from_raw_parts(owner: &'a SEXP, cell: *const RefCell<T>) -> Self

Borrow a receiver after its type and argument aliases have been checked.

§Safety

R’s main thread; cell must point to the live RefCell<T> owned by owner, whose initialized sidecar slots use T’s layout. Its SEXP must stay rooted for 'a; the slot reference alone does not root it. The cell must remain valid for 'a.

Trait Implementations§

Source§

impl<T: TypedExternal + ?Sized + Debug> Debug for ExternalPtrRef<'_, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: TypedExternal + ?Sized> Deref for ExternalPtrRef<'_, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: TypedExternal + ?Sized + Display> Display for ExternalPtrRef<'_, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: TypedExternal + ?Sized> Owner for ExternalPtrRef<'_, T>

Source§

impl<T: TypedExternal + ?Sized> SidecarOwner<T> for ExternalPtrRef<'_, T>

Source§

fn __mx_read(&self) -> SidecarRead<'_, T>

The value, borrowed shared, with its R object; or, for a Saved handle, the restored pointer alone.

Auto Trait Implementations§

§

impl<'a, T> !RefUnwindSafe for ExternalPtrRef<'a, T>

§

impl<'a, T> !Send for ExternalPtrRef<'a, T>

§

impl<'a, T> !Sync for ExternalPtrRef<'a, T>

§

impl<'a, T> !UnwindSafe for ExternalPtrRef<'a, T>

§

impl<'a, T> Freeze for ExternalPtrRef<'a, T>
where Shared<'a, T>: Freeze, T: ?Sized,

§

impl<'a, T> Unpin for ExternalPtrRef<'a, T>
where Shared<'a, T>: Unpin, T: ?Sized,

§

impl<'a, T> UnsafeUnpin for ExternalPtrRef<'a, T>
where Shared<'a, T>: UnsafeUnpin, T: ?Sized,

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> RDebug for T
where T: Debug,

Source§

fn debug_str(&self) -> String

Get a compact debug string representation.
Source§

fn debug_str_pretty(&self) -> String

Get a pretty-printed debug string with indentation.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDebug_debug_str_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDebug,

Method shim for RDebug::debug_str. Read more
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDebug_debug_str_pretty_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDebug,

Method shim for RDebug::debug_str_pretty. Read more
Source§

impl<T> RDisplay for T
where T: Display,

Source§

fn as_r_string(&self) -> String

Convert to a user-friendly string.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDisplay_as_r_string_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDisplay,

Method shim for RDisplay::as_r_string. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.