forked from extendr/extendr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#[extendr]
-impl: Return the right reference (extendr#726)
* extendrtests: added an integration test * add test where other is of type `&Self`. why not? * use `cast` instead of `as` * added a (private) symbol from libR-sys necessary in `#[extendr]`-impl. * Apply suggestions from code review Co-authored-by: Ilia Kosenkov <ilia.kosenkov.at.gm@gmail.com> * split off externalptr tests instead of submodule --------- Co-authored-by: Ilia Kosenkov <ilia.kosenkov.at.gm@gmail.com>
- Loading branch information
1 parent
13e4e4b
commit 9d548d3
Showing
15 changed files
with
2,442 additions
and
1,429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use extendr_api::prelude::*; | ||
|
||
// Class for testing | ||
#[derive(Default, Debug, Clone, Copy)] | ||
struct Wrapper { | ||
a: i32, | ||
} | ||
|
||
/// Class for testing (exported) | ||
/// @examples | ||
/// x <- Wrapper$new() | ||
/// x$a() | ||
/// x$set_a(10) | ||
/// x$a() | ||
/// @export | ||
#[extendr] | ||
impl Wrapper { | ||
/// Method for making a new object. | ||
fn new() -> Self { | ||
Self { a: 0 } | ||
} | ||
|
||
/// Method for setting stuff. | ||
/// @param x a number | ||
fn set_a(&mut self, x: i32) { | ||
self.a = x; | ||
} | ||
|
||
/// Method for getting stuff. | ||
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 (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) -> &Wrapper { | ||
self | ||
} | ||
|
||
/// Method for getting one's ref mut (explicit) self. | ||
fn me_explicit_mut(&mut self) -> &mut Wrapper { | ||
self | ||
} | ||
|
||
fn max_ref(&self, other: &'static Wrapper) -> &Self { | ||
if self.a > other.a { | ||
self | ||
} else { | ||
other | ||
} | ||
} | ||
|
||
/// `offset` does nothing. | ||
fn max_ref_offset(&self, other: &'static Wrapper, _offset: i32) -> &Self { | ||
if self.a > other.a { | ||
self | ||
} else { | ||
other | ||
} | ||
} | ||
|
||
fn max_ref2(&self, other: &'static Self) -> &Self { | ||
if self.a > other.a { | ||
self | ||
} else { | ||
other | ||
} | ||
} | ||
} | ||
|
||
// Macro to generate exports | ||
extendr_module! { | ||
mod externalptr; | ||
impl Wrapper; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.