savvy-bindgen

Crates.iosavvy-bindgen
lib.rssavvy-bindgen
version0.8.0
sourcesrc
created_at2023-09-25 13:42:01.936169
updated_at2024-10-31 01:00:15.274171
descriptionParse Rust functions, and generate C and R code
homepage
repositoryhttps://github.com/yutannihilation/savvy/
max_upload_size
id982712
size99,427
Hiroaki Yutani (yutannihilation)

documentation

README

savvy-bindgen

Parse Rust functions, and generate C and R code.

For the full details, please read savvy's crate documentation.

/// Convert to Upper-case
/// 
/// @param x A character vector.
/// @export
#[savvy]
fn to_upper(x: StringSexp) -> savvy::Result<savvy::Sexp> {
    // Use `Owned{type}Sexp` to allocate an R vector for output.
    let mut out = OwnedStringSexp::new(x.len())?;

    for (i, e) in x.iter().enumerate() {
        // To Rust, missing value is an ordinary value. In `&str`'s case, it's just "NA".
        // You have to use `.is_na()` method to distinguish the missing value.
        if e.is_na() {
            // Set the i-th element to NA
            out.set_na(i)?;
            continue;
        }

        let e_upper = e.to_uppercase();
        out.set_elt(i, e_upper.as_str())?;
    }

    out.into()
}
Commit count: 219

cargo fmt