Skip to main content

RThreadBuilder

Struct RThreadBuilder 

Source
pub struct RThreadBuilder {
    stack_size: usize,
    name: Option<String>,
}
Expand description

Builder for spawning threads with R-appropriate stack sizes.

This builder is always available and configures threads with stack sizes suitable for R workloads (8 MiB default, vs Rust’s 2 MiB default).

When the nonapi feature is enabled, spawned threads also automatically disable R’s stack checking via StackCheckGuard, allowing R API calls from the thread.

§Example

use miniextendr_api::thread::RThreadBuilder;

let handle = RThreadBuilder::new()
    .stack_size(16 * 1024 * 1024)  // 16 MiB
    .name("r-worker".to_string())
    .spawn(|| {
        // With `nonapi`: R API calls safe here
        // Without `nonapi`: Just a thread with correct stack size
    })?;

Fields§

§stack_size: usize§name: Option<String>

Implementations§

Source§

impl RThreadBuilder

Source

pub fn new() -> Self

Create a new builder with default settings.

Default stack size is DEFAULT_R_STACK_SIZE (8 MiB).

Source

pub fn stack_size(self, size: usize) -> Self

Set the stack size for the thread.

R typically requires more stack space than Rust’s default 2 MiB. The default is 8 MiB to match typical R installations.

Source

pub fn name(self, name: String) -> Self

Set the name for the thread (for debugging).

Source

pub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Spawn the thread with the configured settings.

With nonapi feature: automatically disables R’s stack checking. Without nonapi feature: just spawns with the configured stack size.

Source

pub fn spawn_join<F, T>(self, f: F) -> Result<T>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Spawn and immediately join, returning the result.

Convenience method for synchronous R calls on a separate thread.

§Example
let result = RThreadBuilder::new()
    .spawn_join(|| unsafe { miniextendr_api::ffi::Rf_ScalarInteger_unchecked(42) })
    .unwrap();

Trait Implementations§

Source§

impl Default for RThreadBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> RDefault for T
where T: Default,

Source§

fn default() -> T

Create a new instance with default values.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.