41 releases (5 breaking)

new 0.6.3 May 5, 2024
0.6.1 Apr 26, 2024
0.4.1 Mar 30, 2024
0.1.19 Dec 17, 2023
0.1.16 Oct 16, 2023

#1381 in Rust patterns

Download history 94/week @ 2024-01-13 54/week @ 2024-01-20 147/week @ 2024-01-27 126/week @ 2024-02-03 545/week @ 2024-02-10 79/week @ 2024-02-17 92/week @ 2024-02-24 453/week @ 2024-03-02 628/week @ 2024-03-09 77/week @ 2024-03-16 614/week @ 2024-03-23 637/week @ 2024-03-30 172/week @ 2024-04-06 745/week @ 2024-04-13 334/week @ 2024-04-20 41/week @ 2024-04-27

1,437 downloads per month
Used in 3 crates (2 directly)

MIT license

83KB
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

~0.3–0.8MB
~19K SLoC