Expand description
Wrapper helpers to force specific IntoR representations.
This module provides two approaches for controlling how Rust types are converted to R:
§1. As* Wrappers (Call-site Control)
Use these wrappers when you want to override the conversion for a single return value:
AsList<T>: ConvertTto an R list viaIntoListAsExternalPtr<T>: ConvertTto an R external pointerAsRNative<T>: Convert scalarTto a length-1 R vector
ⓘ
#[miniextendr]
fn get_data() -> AsList<MyStruct> {
AsList(MyStruct { x: 1, y: 2 })
}§2. Prefer* Derive Macros (Type-level Control)
Use these derives when a type should always use a specific conversion:
#[derive(IntoList, PreferList)]: Type always converts to R list#[derive(ExternalPtr, PreferExternalPtr)]: Type always converts to external pointer#[derive(RNativeType, PreferRNativeType)]: Newtype always converts to native R scalar
ⓘ
#[derive(IntoList, PreferList)]
struct Point { x: f64, y: f64 }
#[miniextendr]
fn make_point() -> Point { // Automatically becomes R list
Point { x: 1.0, y: 2.0 }
}§3. #[miniextendr(return = "...")] Attribute
Use this when you want to control conversion for a specific #[miniextendr] function
without modifying the type itself:
return = "list": Wrap result inAsListreturn = "externalptr": Wrap result inAsExternalPtrreturn = "native": Wrap result inAsRNative
ⓘ
#[miniextendr(return = "list")]
fn get_as_list() -> MyStruct {
MyStruct { x: 1 }
}§Choosing the Right Approach
| Situation | Recommended Approach |
|---|---|
| Type should always convert one way | Prefer* derive |
| Override conversion for one function | As* wrapper or return attribute |
| Type has multiple valid representations | Don’t use Prefer*; use As* or return |
Structs§
- AsDisplay
- Wrap a
T: Displayand convert it to an R character scalar. - AsDisplay
Vec - Wrap a
Vec<T: Display>and convert it to an R character vector. - AsExternal
Ptr - Wrap a value and convert it to an R external pointer when returned from Rust.
- AsFrom
Str - Wrap a parsed
T: FromStrfrom an R character scalar. - AsFrom
StrVec - Wrap a
Vec<T: FromStr>parsed from an R character vector. - AsList
- Wrap a value and convert it to an R list via
IntoListwhen returned from Rust. - AsNamed
List - Wrap a tuple pair collection and convert it to a named R list (VECSXP).
- AsNamed
Vector - Wrap a tuple pair collection and convert it to a named atomic R vector (INTSXP, REALSXP, LGLSXP, RAWSXP, or STRSXP).
- AsRNative
- Wrap a scalar
RNativeTypeand force native R vector conversion. - Collect
- Write an
ExactSizeIteratorof native R types directly into an R vector. - CollectNA
- Write an
ExactSizeIteratorofOption<T>directly into an R vector with NA support. - CollectNA
Int - Write an
ExactSizeIteratorofOption<i32>directly into an R integer vector with NA. - Collect
Strings - Write an
ExactSizeIteratorofStringdirectly into an R character vector. - Data
Frame - Convert row-oriented data into a column-oriented R data.frame.
- ToData
Frame - Wrap a value and convert it to an R data.frame via
IntoDataFramewhen returned from Rust.
Traits§
- AsExternal
PtrExt - Extension trait for wrapping values as
AsExternalPtr. - AsList
Ext - Extension trait for wrapping values as
AsList. - AsNamed
List Ext - Extension trait for wrapping tuple pair collections as
AsNamedList. - AsNamed
Vector Ext - Extension trait for wrapping tuple pair collections as
AsNamedVector. - AsRNative
Ext - Extension trait for wrapping values as
AsRNative. - Into
Data Frame - Trait for types that can be converted into R data frames.
- ToData
Frame Ext - Extension trait for wrapping values as
ToDataFrame.
Functions§
- named_
vector_ 🔒from_ pairs - Shared helper: build a named atomic vector from an owning iterator of (key, value) pairs.