Skip to content

Commit

Permalink
tests: extendrtests now tests the extendr-impl block ref/mut Self return
Browse files Browse the repository at this point in the history
  • Loading branch information
CGMossa committed Feb 4, 2024
1 parent 23f6405 commit 6222852
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 18 deletions.
10 changes: 9 additions & 1 deletion tests/extendrtests/R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,15 @@ MySubmoduleClass$set_a <- function(x) invisible(.Call(wrap__MySubmoduleClass__se

MySubmoduleClass$a <- function() .Call(wrap__MySubmoduleClass__a, self)

MySubmoduleClass$me <- function() .Call(wrap__MySubmoduleClass__me, self)
MySubmoduleClass$me_owned <- function() .Call(wrap__MySubmoduleClass__me_owned, self)

MySubmoduleClass$me_ref <- function() .Call(wrap__MySubmoduleClass__me_ref, self)

MySubmoduleClass$me_mut <- function() .Call(wrap__MySubmoduleClass__me_mut, self)

MySubmoduleClass$me_explicit_ref <- function() .Call(wrap__MySubmoduleClass__me_explicit_ref, self)

MySubmoduleClass$me_explicit_mut <- function() .Call(wrap__MySubmoduleClass__me_explicit_mut, self)

#' @rdname MySubmoduleClass
#' @usage NULL
Expand Down
2 changes: 1 addition & 1 deletion tests/extendrtests/man/MySubmoduleClass.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 31 additions & 4 deletions tests/extendrtests/src/rust/src/submodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn hello_submodule() -> &'static str {
}

// Class for testing
#[derive(Default, Debug)]
#[derive(Default, Debug, Clone, Copy)]
struct MySubmoduleClass {
a: i32,
}
Expand Down Expand Up @@ -37,13 +37,40 @@ impl MySubmoduleClass {
fn a(&self) -> i32 {
self.a
}

// NOTE: Cannot move ownership, as that concept is incompatible with bridging
// data from R to Rust
// fn myself(self) -> Self {
// self
// }

/// Method for getting one's self.
fn me(&self) -> &Self {
/// Method for getting one's (by way of a copy) self.
fn me_owned(&self) -> Self {
// only possible due to `derive(Clone, Copy)`
*self
}

/// Method for getting one's (ref) self.
fn me_ref(&self) -> &Self {
self
}

/// Method for getting one's (ref mut) self.
fn me_mut(&mut self) -> &mut Self {
self
}
}

/// Method for getting one's ref (explicit) self.
fn me_explicit_ref(&self) -> &MySubmoduleClass {
self
}

/// Method for getting one's ref mut (explicit) self.
fn me_explicit_mut(&mut self) -> &mut MySubmoduleClass {
self
}
}

// Macro to generate exports
extendr_module! {
mod submodule;
Expand Down
Loading

0 comments on commit 6222852

Please sign in to comment.