pub struct NamedList {
list: List,
index: HashMap<String, usize>,
}Expand description
A named list with O(1) name-based element lookup.
Wraps a List and builds a HashMap<String, usize> index of element names
on construction. Use this when you need to access multiple elements by name
from the same list — each lookup is O(1) instead of O(n).
§When to Use
| Pattern | Type |
|---|---|
| Single named lookup | List::get_named is fine |
| Multiple named lookups | NamedList (O(n) build + O(1) per lookup) |
| Positional access only | List — no indexing overhead |
§Name Handling
NAand empty-string names are excluded from the index- If duplicate names exist, the last occurrence wins
- Positional access via
get_indexis always available
Fields§
§list: List§index: HashMap<String, usize>Implementations§
Source§impl NamedList
impl NamedList
Sourcepub fn as_data_frame(&self) -> Result<DataFrameView, DataFrameError>
pub fn as_data_frame(&self) -> Result<DataFrameView, DataFrameError>
Promote this named list to a DataFrameView.
Validates that all columns have equal length, then sets the class
attribute to "data.frame" and adds compact integer row.names.
§Errors
Returns DataFrameError::UnequalLengths if columns differ in length.
Source§impl NamedList
impl NamedList
Sourcepub fn new(list: List) -> Option<Self>
pub fn new(list: List) -> Option<Self>
Build a NamedList from a List, indexing all non-empty, non-NA names.
Returns None if the list has no names attribute.
Sourcepub fn get<T>(&self, name: &str) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
pub fn get<T>(&self, name: &str) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
Get an element by name with O(1) lookup, converting to type T.
Returns None if the name is not found or conversion fails.
Sourcepub fn get_raw(&self, name: &str) -> Option<SEXP>
pub fn get_raw(&self, name: &str) -> Option<SEXP>
Get a raw SEXP element by name with O(1) lookup.
Sourcepub fn get_index<T>(&self, idx: isize) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
pub fn get_index<T>(&self, idx: isize) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
Get element at 0-based index and convert to type T.
Falls through to List::get_index — no name lookup involved.
Trait Implementations§
Source§impl IntoR for NamedList
impl IntoR for NamedList
Source§type Error = Infallible
type Error = Infallible
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Auto Trait Implementations§
impl Freeze for NamedList
impl RefUnwindSafe for NamedList
impl Send for NamedList
impl Sync for NamedList
impl Unpin for NamedList
impl UnsafeUnpin for NamedList
impl UnwindSafe for NamedList
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeEq<MaybeUninit<T>> for T
impl<T> SizeEq<MaybeUninit<T>> for T
type CastFrom = CastSizedExact
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreimpl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> InvariantsEq<ManuallyDrop<T>> for Twhere
T: ?Sized,
impl<T> InvariantsEq<T> for Twhere
T: ?Sized,
impl<T> InvariantsEq<Unalign<T>> for T
impl<T> InvariantsEq<Wrapping<T>> for T
impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T
impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T
impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
C: CastExact<Src, Dst>,
Dst: TransmuteFrom<Src, SV, DV> + TryTransmuteFromPtr<Src, A, SV, DV, C, R> + ?Sized,
Src: ?Sized,
impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: MutationCompatible<Src, A, SV, DV, R> + ?Sized,
C: CastExact<Src, Dst>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 56 bytes