50 releases (7 breaking)

new 0.8.0 Oct 31, 2024
0.6.8 Sep 17, 2024
0.6.5 Jul 2, 2024
0.4.1 Mar 30, 2024
0.1.16 Oct 16, 2023

#1983 in Procedural macros

Download history 63/week @ 2024-07-10 100/week @ 2024-07-17 122/week @ 2024-07-24 167/week @ 2024-07-31 14/week @ 2024-08-07 74/week @ 2024-08-14 231/week @ 2024-08-21 313/week @ 2024-08-28 691/week @ 2024-09-04 611/week @ 2024-09-11 725/week @ 2024-09-18 293/week @ 2024-09-25 201/week @ 2024-10-02 324/week @ 2024-10-09 1027/week @ 2024-10-16 685/week @ 2024-10-23

2,300 downloads per month
Used in savvy

MIT license

105KB
2.5K SLoC

savvy-macro

Generate R-ready Rust functions by adding #[savvy] macro.

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

~270–730KB
~17K SLoC