| Crates.io | savvy-macro |
| lib.rs | savvy-macro |
| version | 0.8.13 |
| created_at | 2023-09-25 13:44:14.945085+00 |
| updated_at | 2025-07-28 03:50:01.514725+00 |
| description | Generate R-ready Rust functions by adding `#[savvy]` macro |
| homepage | https://yutannihilation.github.io/savvy/guide/ |
| repository | https://github.com/yutannihilation/savvy/ |
| max_upload_size | |
| id | 982718 |
| size | 32,775 |
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()
}