From ab2144e3b96affc5e12c4482f920ad4aaeb179e8 Mon Sep 17 00:00:00 2001 From: Mossa Date: Sun, 17 Mar 2024 22:13:26 +0100 Subject: [PATCH] Doc update: IntoRobj and TryFromRobj needs to refer to each other --- extendr-macros/src/lib.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/extendr-macros/src/lib.rs b/extendr-macros/src/lib.rs index 32cf275124..0f26051ff4 100644 --- a/extendr-macros/src/lib.rs +++ b/extendr-macros/src/lib.rs @@ -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) @@ -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 @@ -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 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 @@ -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)