pub struct IterListData<I: Iterator<Item = SEXP>> {
len: usize,
iter: RefCell<Option<I>>,
cached: Cell<usize>,
cache: OnceCell<PoolRoot>,
}Expand description
Iterator-backed list data with a rooted cache of the yielded R objects.
Construction does not advance the iterator or allocate R storage. The first
in-bounds read allocates one list of the declared length, and each yielded
object goes into it before the next call to Iterator::next. So the
iterator can return fresh, unprotected objects, as in
(0..n).map(|i| vec![i].into_sexp()). It remains responsible for rooting
any R objects it keeps between calls.
The cache list is rooted in the same pool as owning ExternalPtr handles.
The adapter roots it itself, so it is safe before it is attached to an
ALTREP object, and releases it on drop. That pool releases in O(1) in any
order: R’s finalizers drop ALTREP owners newest first, whatever order their
caches were created in.
Reads generate only the requested prefix. Elements past the end of a short
source read as R NULL; the source is dropped on its first None and never
resumed. An infinite source is consumed only up to the declared length.
Clone copies the cache list, sharing its elements as R’s
shallow_duplicate() does, and clones the remaining iterator without
advancing it. Serialization realizes the declared prefix, NULLs included,
and restoration needs no I. Delegate these data traits from a concrete
#[derive(AltrepList)] class with
#[altrep(manual, serialize, duplicate = "clone")].
The adapter is !Send + !Sync: build, read, clone and drop it on R’s main
thread.
use miniextendr_api::{IntoR, altrep_data::IterListData};
let data = IterListData::from_exact_iter((0..5).map(|x| vec![x, x + 1].into_sexp()));Fields§
§len: usize§iter: RefCell<Option<I>>§cached: Cell<usize>§cache: OnceCell<PoolRoot>Implementations§
Source§impl<I: Iterator<Item = SEXP>> IterListData<I>
impl<I: Iterator<Item = SEXP>> IterListData<I>
Source§impl<I: ExactSizeIterator<Item = SEXP>> IterListData<I>
impl<I: ExactSizeIterator<Item = SEXP>> IterListData<I>
Sourcepub fn from_exact_iter(iter: I) -> Self
pub fn from_exact_iter(iter: I) -> Self
Create a lazy adapter using the iterator’s remaining length.
Trait Implementations§
Source§impl<I: Iterator<Item = SEXP>> AltListData for IterListData<I>
impl<I: Iterator<Item = SEXP>> AltListData for IterListData<I>
Source§impl<I: Iterator<Item = SEXP>> AltrepLen for IterListData<I>
impl<I: Iterator<Item = SEXP>> AltrepLen for IterListData<I>
Source§fn altrep_len(&self) -> usize
fn altrep_len(&self) -> usize
Source§fn altrep_is_empty(&self) -> bool
fn altrep_is_empty(&self) -> bool
Source§impl<I: Iterator<Item = SEXP>> AltrepSerialize for IterListData<I>
impl<I: Iterator<Item = SEXP>> AltrepSerialize for IterListData<I>
Source§fn serialized_state(&self) -> SEXP
fn serialized_state(&self) -> SEXP
Auto Trait Implementations§
impl<I> !Freeze for IterListData<I>
impl<I> !RefUnwindSafe for IterListData<I>
impl<I> !Send for IterListData<I>
impl<I> !Sync for IterListData<I>
impl<I> Unpin for IterListData<I>
impl<I> UnsafeUnpin for IterListData<I>
impl<I> UnwindSafe for IterListData<I>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConsumingFallible for Twhere
T: Clone,
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§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 moreLayout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.