Skip to main content

AltrepIteratorExt

Trait AltrepIteratorExt 

Source
pub trait AltrepIteratorExt: Iterator + Sized {
    // Provided methods
    fn into_altrep_data(
        self,
        len: usize,
    ) -> <Self::Item as AltrepIteratorItem>::Data<Self>
       where Self::Item: AltrepIteratorItem { ... }
    fn into_altrep_data_exact(
        self,
    ) -> <Self::Item as AltrepIteratorItem>::Data<Self>
       where Self: ExactSizeIterator,
             Self::Item: AltrepIteratorItem { ... }
}
Expand description

ALTREP data constructors for every iterator, including third-party adapters.

Exact-size iterators can supply their remaining length. Other iterators need an explicit finite prefix length; neither constructor counts or collects them. Borrowed iterators can be used as data adapters, but an R-owned class must own its source for the whole R lifetime.

The item type picks the data family, so an unsuffixed integer literal can’t fall back to i32 here: write 0..6i32, not 0..6.

use miniextendr_api::{AltrepIteratorExt, AltIntegerData, AltrepLen};
let data = (0..6i32).map(|x| x * 2).into_altrep_data_exact();
assert_eq!(data.altrep_len(), 6);
assert_eq!(data.elt(2), 4);

Provided Methods§

Source

fn into_altrep_data( self, len: usize, ) -> <Self::Item as AltrepIteratorItem>::Data<Self>
where Self::Item: AltrepIteratorItem,

Cache a finite prefix in the item’s chosen ALTREP data family.

Source

fn into_altrep_data_exact( self, ) -> <Self::Item as AltrepIteratorItem>::Data<Self>

Use the iterator’s exact remaining length without advancing it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§