Skip to content

Commit

Permalink
Doc update: IntoRobj and TryFromRobj needs to refer to each other
Browse files Browse the repository at this point in the history
  • Loading branch information
CGMossa committed Mar 17, 2024
1 parent b2a2a77 commit ab2144e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion extendr-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ pub fn Rraw(item: TokenStream) -> TokenStream {
/// # }
/// # Ok::<(), extendr_api::Error>(())
/// ```
///
/// See [`IntoRobj`] for converting arbitrary Rust types into R type by using
/// R's list / `List`.
///
#[proc_macro_derive(TryFromRobj)]
pub fn derive_try_from_robj(item: TokenStream) -> TokenStream {
list_struct::derive_try_from_robj(item)
Expand All @@ -233,7 +237,11 @@ pub fn derive_try_from_robj(item: TokenStream) -> TokenStream {
/// This allows the struct to be converted to a named list in R,
/// where the list names correspond to the field names of the Rust struct.
///
/// Note that the R list may contain more fields, than those corresponding
/// to the Rust type.
///
/// # Examples
///
/// In the below example, `converted` contains an R list object with the same fields as the
/// `Foo` struct.
/// ```ignore
Expand All @@ -255,7 +263,13 @@ pub fn derive_try_from_robj(item: TokenStream) -> TokenStream {
/// # }
/// # Ok::<(), extendr_api::Error>(())
/// ```
///
/// See [`TryFromRobj`] for a `derive`-macro in the other direction, i.e.
/// instantiation of a rust type, by an R list with fields corresponding to
/// said type.
///
/// # Details
///
/// Note, the `From<Struct> for Robj` behaviour is different from what is obtained by applying the standard `#[extendr]` macro
/// to an `impl` block. The `#[extendr]` behaviour returns to R a **pointer** to Rust memory, and generates wrapper functions for calling
/// Rust functions on that pointer. The implementation from `#[derive(IntoRobj)]` actually converts the Rust structure
Expand Down Expand Up @@ -286,7 +300,6 @@ pub fn derive_into_robj(item: TokenStream) -> TokenStream {
/// assert_eq!(df[0], r!([0, 1]));
/// assert_eq!(df[1], r!(["abc", "xyz"]));
/// ```
#[proc_macro_derive(IntoDataFrameRow)]
pub fn derive_into_dataframe(item: TokenStream) -> TokenStream {
dataframe::derive_into_dataframe(item)
Expand Down

0 comments on commit ab2144e

Please sign in to comment.