pub struct ExternalPtrMut<'a, T: TypedExternal + ?Sized> {
value: Exclusive<'a, T>,
owner: &'a SEXP,
_main_thread: PhantomData<*mut ()>,
}Expand description
An exclusive borrow of a Rust value together with its R object.
ExternalPtr::borrow_mut makes one, and
a #[miniextendr] function or method takes one as a parameter (or as
self: ExternalPtrMut<'_, Self>) when it needs the R object as well as
the value, like ExternalPtrRef. Dereferencing gives mutable access to
the Rust fields; the sidecar setters use the R object. There is no
consuming API.
The view holds an exclusive borrow of the value’s RefCell for its whole
lifetime: any other borrow of the value meanwhile raises the R error of
class miniextendr_borrow_conflict. Pass it on without moving it with
rb_mut, or as a shared view with rb.
A view borrows its handle for as long as it lives:
use miniextendr_api::{ExternalPtr, ExternalPtrMut, ExternalPtrRef, TypedExternal};
fn overlap<T: TypedExternal>(owner: &mut ExternalPtr<T>) {
let mut first = owner.borrow_mut();
let second = owner.borrow();
let _ = (&mut *first, second);
}A reborrow ends before the view is used again:
use miniextendr_api::{ExternalPtrMut, TypedExternal};
fn twice<T: TypedExternal>(view: &mut ExternalPtrMut<'_, T>) {
let first = view.rb_mut();
let second = view.rb_mut();
let _ = (first, second);
}Fields§
§value: Exclusive<'a, T>§owner: &'a SEXP§_main_thread: PhantomData<*mut ()>Implementations§
Source§impl<'a, T: TypedExternal + ?Sized> ExternalPtrMut<'a, T>
impl<'a, T: TypedExternal + ?Sized> ExternalPtrMut<'a, T>
Sourcepub(super) fn from_guard(owner: &'a SEXP, guard: RefMut<'a, T>) -> Self
pub(super) fn from_guard(owner: &'a SEXP, guard: RefMut<'a, T>) -> Self
Hold guard, an exclusive 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 as long as this view isn’t used mutably.
Sourcepub fn rb_mut(&mut self) -> ExternalPtrMut<'_, T>
pub fn rb_mut(&mut self) -> ExternalPtrMut<'_, T>
An exclusive view of the same value for a shorter lifetime, to pass on without moving this one.
Source§impl<'a, T: TypedExternal> ExternalPtrMut<'a, T>
impl<'a, T: TypedExternal> ExternalPtrMut<'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 ExternalPtrMut<'_, T>
impl<T: TypedExternal + ?Sized + Debug> Debug for ExternalPtrMut<'_, T>
Source§impl<T: TypedExternal + ?Sized> Deref for ExternalPtrMut<'_, T>
impl<T: TypedExternal + ?Sized> Deref for ExternalPtrMut<'_, T>
Source§impl<T: TypedExternal + ?Sized> DerefMut for ExternalPtrMut<'_, T>
impl<T: TypedExternal + ?Sized> DerefMut for ExternalPtrMut<'_, T>
Source§impl<T: TypedExternal + ?Sized + Display> Display for ExternalPtrMut<'_, T>
impl<T: TypedExternal + ?Sized + Display> Display for ExternalPtrMut<'_, T>
impl<T: TypedExternal + ?Sized> Owner for ExternalPtrMut<'_, T>
Source§impl<T: TypedExternal + ?Sized> SidecarOwner<T> for ExternalPtrMut<'_, T>
impl<T: TypedExternal + ?Sized> SidecarOwner<T> for ExternalPtrMut<'_, T>
Source§fn __mx_read(&self) -> SidecarRead<'_, T>
fn __mx_read(&self) -> SidecarRead<'_, T>
Saved
handle, the restored pointer alone.Source§impl<T: TypedExternal + ?Sized> SidecarOwnerMut<T> for ExternalPtrMut<'_, T>
impl<T: TypedExternal + ?Sized> SidecarOwnerMut<T> for ExternalPtrMut<'_, T>
Source§fn __mx_write(&mut self) -> ExternalPtrMut<'_, T>
fn __mx_write(&mut self) -> ExternalPtrMut<'_, T>
Auto Trait Implementations§
impl<'a, T> !RefUnwindSafe for ExternalPtrMut<'a, T>
impl<'a, T> !Send for ExternalPtrMut<'a, T>
impl<'a, T> !Sync for ExternalPtrMut<'a, T>
impl<'a, T> !UnwindSafe for ExternalPtrMut<'a, T>
impl<'a, T> Freeze for ExternalPtrMut<'a, T>
impl<'a, T> Unpin for ExternalPtrMut<'a, T>
impl<'a, T> UnsafeUnpin for ExternalPtrMut<'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.