Skip to main content

Module named_vector

Module named_vector 

Source
Expand description

Named atomic vector wrapper for HashMap/BTreeMap ↔ named R atomic vector conversions.

By default, HashMap<String, V> and BTreeMap<String, V> convert to/from named R lists (VECSXP). This module provides NamedVector for converting to/from named atomic vectors (INTSXP, REALSXP, LGLSXP, RAWSXP, STRSXP) instead — a more compact and idiomatic representation when values are scalar.

§Example

use std::collections::HashMap;
use miniextendr_api::NamedVector;

#[miniextendr]
fn make_scores() -> NamedVector<HashMap<String, i32>> {
    let mut m = HashMap::new();
    m.insert("alice".into(), 95);
    m.insert("bob".into(), 87);
    NamedVector(m)
}
// In R: make_scores() returns c(alice = 95L, bob = 87L)

Structs§

NamedVector
Wrapper that converts a map to/from a named atomic R vector instead of a named list.

Traits§

AtomicElement
Marker trait for types that can be elements of named atomic R vectors.

Functions§

extract_names_strict 🔒
Extract names from an R SEXP with strict validation.
set_names_on_sexp 🔒
Set names attribute on an R SEXP from a slice of name-like values.