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>
impl<'a, T: TypedExternal + ?Sized> ExternalPtrRef<'a, T>
Sourcepub(super) fn from_guard(owner: &'a SEXP, guard: Ref<'a, T>) -> Self
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.
Sourcepub fn rb(&self) -> ExternalPtrRef<'_, T>
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§impl<'a, T: TypedExternal> ExternalPtrRef<'a, T>
impl<'a, T: TypedExternal> ExternalPtrRef<'a, T>
Source#[doc(hidden)]pub unsafe fn from_raw_parts(owner: &'a SEXP, cell: *const RefCell<T>) -> Self
#[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>
impl<T: TypedExternal + ?Sized + Debug> Debug for ExternalPtrRef<'_, T>
Source§impl<T: TypedExternal + ?Sized> Deref for ExternalPtrRef<'_, T>
impl<T: TypedExternal + ?Sized> Deref for ExternalPtrRef<'_, T>
Source§impl<T: TypedExternal + ?Sized + Display> Display for ExternalPtrRef<'_, T>
impl<T: TypedExternal + ?Sized + Display> Display for ExternalPtrRef<'_, T>
impl<T: TypedExternal + ?Sized> Owner for ExternalPtrRef<'_, T>
Source§impl<T: TypedExternal + ?Sized> SidecarOwner<T> for ExternalPtrRef<'_, T>
impl<T: TypedExternal + ?Sized> SidecarOwner<T> for ExternalPtrRef<'_, T>
Source§fn __mx_read(&self) -> SidecarRead<'_, T>
fn __mx_read(&self) -> SidecarRead<'_, T>
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>
impl<'a, T> Unpin for ExternalPtrRef<'a, T>
impl<'a, T> UnsafeUnpin for ExternalPtrRef<'a, T>
Blanket Implementations§
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> RDebug for Twhere
T: Debug,
impl<T> RDebug for Twhere
T: Debug,
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.