Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use functions from another file in extendr_module! #197

Closed
daniellga opened this issue May 25, 2022 · 2 comments
Closed

use functions from another file in extendr_module! #197

daniellga opened this issue May 25, 2022 · 2 comments

Comments

@daniellga
Copy link

I have the rust/src where the lib.rs and core.rs are put together. I would like to use functions from core.rs in extendr_module!, located in lib.rs. Is it possible to do without too much overhead?

lib.rs:

use extendr_api::prelude::*;
mod core;
use core::load;

// Macro to generate exports.
// This ensures exported functions are registered with R.
// See corresponding C code in `entrypoint.c`.
extendr_module! {
    mod rpackage;
    fn load;
}

core.rs:

use extendr_api::prelude::*;

/// test function
/// @export
#[extendr]
pub fn load() {
...
}

The error is showed on lib.rs, in fn load:

cannot find function `meta__load` in this scope
not found in this scoperustc[E0425](https://doc.rust-lang.org/error-index.html#E0425)
core.rs(13, 1): function `crate::core::meta__load` exists but is inaccessible
@Ilia-Kosenkov
Copy link
Member

I think you need to put extendr_module!{} in each module you are trying to export.
As a side note, I'd suggest to have a single module exposing Rust API to R rather than scatter exported function over multiple files.

@onurcanbektas
Copy link

I think you need to put extendr_module!{} in each module you are trying to export. As a side note, I'd suggest to have a single module exposing Rust API to R rather than scatter exported function over multiple files.

This doesn't work. It gives an error like

Objects listed as exports, but not present in namespace:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants