extendr / rextendr

An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically
https://extendr.github.io/rextendr/
Other
184 stars 27 forks source link

use functions from another file in extendr_module! #197

Closed daniellga closed 2 years ago

daniellga commented 2 years ago

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 commented 2 years ago

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 commented 5 months ago

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: