Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nleroy917 committed Oct 22, 2024
1 parent f2ad6e7 commit b10f09c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
30 changes: 30 additions & 0 deletions bindings/r/src/rust/src/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use extendr_api::prelude::*;

use gtars::io::{read_tokens_from_gtok, write_tokens_to_gtok};

/// Write tokens to a gtok file
/// @export
/// @param filename A string representing the path to the gtok file.
#[extendr(r_name = "write_tokens_to_gtok")]
pub fn r_write_tokens_to_gtok(filename: String, tokens: Vec<i32>) {
let tokens: Vec<u32> = tokens.into_iter().map(|t| t as u32).collect();
let _ = write_tokens_to_gtok(&filename, &tokens);
}

/// Write tokens to a gtok file
/// @export
/// @param filename A string representing the path to the gtok file.
#[extendr(r_name = "read_tokens_from_gtok")]
pub fn r_read_tokens_from_gtok(filename: String) -> Vec<i32> {
read_tokens_from_gtok(&filename)
.unwrap()
.into_iter()
.map(|gtok| gtok as i32)
.collect()
}

extendr_module! {
mod io;
fn r_read_tokens_from_gtok;
fn r_write_tokens_to_gtok;
}
34 changes: 2 additions & 32 deletions bindings/r/src/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,11 @@
use extendr_api::prelude::*;

use gtars::io::{read_tokens_from_gtok, write_tokens_to_gtok};

/// Return string `"Hello world!"` to R.
/// @export
#[extendr]
fn hello_world() -> &'static str {
"Hello world!"
}

/// Write tokens to a gtok file
/// @export
/// @param filename A string representing the path to the gtok file.
#[extendr(r_name = "write_tokens_to_gtok")]
fn r_write_tokens_to_gtok(filename: String, tokens: Vec<i32>) {
let tokens: Vec<u32> = tokens.into_iter().map(|t| t as u32).collect();
let _ = write_tokens_to_gtok(&filename, &tokens);
}

/// Write tokens to a gtok file
/// @export
/// @param filename A string representing the path to the gtok file.
#[extendr(r_name = "read_tokens_from_gtok")]
fn r_read_tokens_from_gtok(filename: String) -> Vec<i32> {
read_tokens_from_gtok(&filename)
.unwrap()
.into_iter()
.map(|gtok| gtok as i32)
.collect()
}
pub mod io;

// Macro to generate exports.
// This ensures exported functions are registered with R.
// See corresponding C code in `entrypoint.c`.
extendr_module! {
mod gtars;
fn hello_world;
fn r_write_tokens_to_gtok;
fn r_read_tokens_from_gtok;
use io;
}

0 comments on commit b10f09c

Please sign in to comment.