Skip to main content

ThreadLocalArenaOps

Trait ThreadLocalArenaOps 

Source
pub trait ThreadLocalArenaOps {
    type Map: MapStorage;

Show 15 methods // Required method fn with_state<R, F: FnOnce(&mut ThreadLocalState<Self::Map>) -> R>( f: F, ) -> R; // Provided methods unsafe fn init() { ... } unsafe fn init_with_capacity(capacity: usize) { ... } unsafe fn protect(x: SEXP) -> SEXP { ... } unsafe fn unprotect(x: SEXP) { ... } unsafe fn try_unprotect(x: SEXP) -> bool { ... } unsafe fn protect_fast(x: SEXP) -> SEXP { ... } unsafe fn unprotect_fast(x: SEXP) { ... } unsafe fn try_unprotect_fast(x: SEXP) -> bool { ... } fn is_protected(x: SEXP) -> bool { ... } fn ref_count(x: SEXP) -> usize { ... } fn len() -> usize { ... } fn is_empty() -> bool { ... } fn capacity() -> usize { ... } unsafe fn clear() { ... }
}
Expand description

Trait providing default implementations for all thread-local arena methods.

Implementors only need to provide with_state to access the thread-local state; all 14 arena methods are provided as defaults.

The define_thread_local_arena! macro generates both the struct and the ThreadLocalArenaOps impl, so this trait is an implementation detail. Import it when calling methods on thread-local arena types:

use miniextendr_api::refcount_protect::{ThreadLocalArena, ThreadLocalArenaOps};
unsafe { ThreadLocalArena::protect(x) };

Required Associated Types§

Source

type Map: MapStorage

The map storage type used by this arena.

Required Methods§

Source

fn with_state<R, F: FnOnce(&mut ThreadLocalState<Self::Map>) -> R>(f: F) -> R

Access the thread-local state.

Implementors route through thread_local! + UnsafeCell.

Provided Methods§

Source

unsafe fn init()

Initialize the arena with default capacity (called automatically on first use).

§Safety

Must be called from the R main thread.

Source

unsafe fn init_with_capacity(capacity: usize)

Initialize the arena with specific capacity.

Use this when you know the expected number of distinct protected values to avoid backing VECSXP growth and map rehashing during operation.

If already initialized, this is a no-op.

§Safety

Must be called from the R main thread.

Source

unsafe fn protect(x: SEXP) -> SEXP

Protect a SEXP, incrementing its reference count.

§Safety

Must be called from the R main thread.

Source

unsafe fn unprotect(x: SEXP)

Unprotect a SEXP.

§Safety

Must be called from the R main thread.

Source

unsafe fn try_unprotect(x: SEXP) -> bool

Try to unprotect a SEXP.

§Safety

Must be called from the R main thread.

Source

unsafe fn protect_fast(x: SEXP) -> SEXP

Protect without checking initialization.

For hot loops where init() or init_with_capacity() has already been called.

§Safety
  • Must be called from the R main thread.
  • The arena must have been initialized via init() or init_with_capacity().
Source

unsafe fn unprotect_fast(x: SEXP)

Unprotect without checking initialization.

For hot loops where init() or init_with_capacity() has already been called.

§Safety
  • Must be called from the R main thread.
  • The arena must have been initialized via init() or init_with_capacity().
Source

unsafe fn try_unprotect_fast(x: SEXP) -> bool

Try to unprotect without checking initialization.

For hot loops where init() or init_with_capacity() has already been called.

§Safety
  • Must be called from the R main thread.
  • The arena must have been initialized via init() or init_with_capacity().
Source

fn is_protected(x: SEXP) -> bool

Check if a SEXP is protected.

Source

fn ref_count(x: SEXP) -> usize

Get reference count.

Source

fn len() -> usize

Number of protected SEXPs.

Source

fn is_empty() -> bool

Check if empty.

Source

fn capacity() -> usize

Get capacity.

Source

unsafe fn clear()

Clear all protections.

§Safety

Must be called from the R main thread.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§