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§
Sourcetype Map: MapStorage
type Map: MapStorage
The map storage type used by this arena.
Required Methods§
Sourcefn with_state<R, F: FnOnce(&mut ThreadLocalState<Self::Map>) -> R>(f: F) -> R
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§
Sourceunsafe fn init()
unsafe fn init()
Initialize the arena with default capacity (called automatically on first use).
§Safety
Must be called from the R main thread.
Sourceunsafe fn init_with_capacity(capacity: usize)
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.
Sourceunsafe fn try_unprotect(x: SEXP) -> bool
unsafe fn try_unprotect(x: SEXP) -> bool
Sourceunsafe fn protect_fast(x: SEXP) -> SEXP
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()orinit_with_capacity().
Sourceunsafe fn unprotect_fast(x: SEXP)
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()orinit_with_capacity().
Sourceunsafe fn try_unprotect_fast(x: SEXP) -> bool
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()orinit_with_capacity().
Sourcefn is_protected(x: SEXP) -> bool
fn is_protected(x: SEXP) -> bool
Check if a SEXP is protected.
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.