diff --git a/extendr-api/tests/extendr_enum_tests.rs b/extendr-api/tests/extendr_enum_tests.rs index 15ac499952..631da8139d 100644 --- a/extendr-api/tests/extendr_enum_tests.rs +++ b/extendr-api/tests/extendr_enum_tests.rs @@ -19,6 +19,7 @@ fn tst_enum_wrapper(_x: Robj, enum_fct: Model) { } #[extendr(use_try_from = true)] +// #[extendr] fn my_enum(e: &str) -> Model { match e.to_uppercase().as_str() { "A" => Model::MeanModel, diff --git a/tests/extendrtests/R/extendr-wrappers.R b/tests/extendrtests/R/extendr-wrappers.R index 3a056ea879..624a4c5701 100644 --- a/tests/extendrtests/R/extendr-wrappers.R +++ b/tests/extendrtests/R/extendr-wrappers.R @@ -129,6 +129,8 @@ tst_altinteger <- function() .Call(wrap__tst_altinteger) tst_enum_wrapper <- function(`_x`, enum_fct) invisible(.Call(wrap__tst_enum_wrapper, `_x`, enum_fct)) +my_enum <- function(e) .Call(wrap__my_enum, e) + #' Class for testing (exported) #' @examples #' x <- MyClass$new() diff --git a/tests/extendrtests/src/rust/src/enum_as_factor.rs b/tests/extendrtests/src/rust/src/enum_as_factor.rs index b82429e673..95782db126 100644 --- a/tests/extendrtests/src/rust/src/enum_as_factor.rs +++ b/tests/extendrtests/src/rust/src/enum_as_factor.rs @@ -17,7 +17,18 @@ fn tst_enum_wrapper(_x: Robj, enum_fct: Model) { }; } +#[extendr(use_try_from = true)] +fn my_enum(e: &str) -> Model { + match e.to_uppercase().as_str() { + "A" => Model::A, + "B" => Model::B, + "C" => Model::C, + _ => unimplemented!(), + } +} + extendr_module! { mod enum_as_factor; fn tst_enum_wrapper; + fn my_enum; }