57 releases

0.8.6 Feb 8, 2025
0.8.3 Jan 11, 2025
0.8.2 Dec 25, 2024
0.8.1 Nov 17, 2024
0.1.16 Oct 16, 2023

#2140 in Procedural macros

Download history 652/week @ 2024-10-28 135/week @ 2024-11-04 346/week @ 2024-11-11 228/week @ 2024-11-18 169/week @ 2024-11-25 96/week @ 2024-12-02 639/week @ 2024-12-09 107/week @ 2024-12-16 187/week @ 2024-12-23 32/week @ 2024-12-30 503/week @ 2025-01-06 431/week @ 2025-01-13 61/week @ 2025-01-20 190/week @ 2025-01-27 663/week @ 2025-02-03 470/week @ 2025-02-10

1,641 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

~245–700KB
~17K SLoC