56 releases

0.8.3 Jan 11, 2025
0.8.2 Dec 25, 2024
0.8.1 Nov 17, 2024
0.6.5 Jul 2, 2024
0.1.16 Oct 16, 2023

#205 in Procedural macros

Download history 282/week @ 2024-10-04 429/week @ 2024-10-11 935/week @ 2024-10-18 872/week @ 2024-10-25 216/week @ 2024-11-01 153/week @ 2024-11-08 353/week @ 2024-11-15 239/week @ 2024-11-22 130/week @ 2024-11-29 579/week @ 2024-12-06 215/week @ 2024-12-13 177/week @ 2024-12-20 38/week @ 2024-12-27 94/week @ 2025-01-03 577/week @ 2025-01-10 356/week @ 2025-01-17

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

MIT license

96KB
2.5K 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

~190–690KB
~16K SLoC