52 releases (7 breaking)

0.8.1 Nov 17, 2024
0.7.2 Oct 27, 2024
0.6.5 Jul 2, 2024
0.4.1 Mar 30, 2024
0.1.16 Oct 16, 2023

#189 in Procedural macros

Download history 124/week @ 2024-08-17 277/week @ 2024-08-24 751/week @ 2024-08-31 309/week @ 2024-09-07 929/week @ 2024-09-14 402/week @ 2024-09-21 370/week @ 2024-09-28 305/week @ 2024-10-05 524/week @ 2024-10-12 832/week @ 2024-10-19 865/week @ 2024-10-26 184/week @ 2024-11-02 205/week @ 2024-11-09 317/week @ 2024-11-16 213/week @ 2024-11-23 106/week @ 2024-11-30

860 downloads per month
Used in 3 crates (2 directly)

MIT license

91KB
2K SLoC

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()
}

Dependencies

~220–720KB
~17K SLoC