Skip to main content

AsLegacyRange

Trait AsLegacyRange 

Source
trait AsLegacyRange<T> {
    // Required methods
    fn as_legacy_range(&self) -> &Range<T> ;
    fn as_legacy_range_mut(&mut self) -> &mut Range<T> ;
}
Expand description

For these implementations, SpecRangeSetup calculates the number of iterations that will be needed and stores that in iter.end.

The various iterator implementations then rely on that to not need overflow checking, letting loops just be counted instead.

These only work for unsigned types, and will need to be reworked if you want to use it to specialize on signed types.

Currently these are only implemented for integers up to usize due to correctness issues around ExactSizeIterator impls on 16bit platforms. And since ExactSizeIterator is a prerequisite for backwards iteration and we must consistently specialize backwards and forwards iteration that makes the situation complicated enough that it’s not covered for now.

After SpecRangeSetup::setup, both Range<T> and its new-range wrapper RangeIter<T> carry the cursor and countdown in the same underlying legacy Range. This accessor exposes that shared range so one specialization can serve both: it is an identity for Range<T> and unwraps the newtype for RangeIter<T>, so it compiles away.

Required Methods§

Source

fn as_legacy_range(&self) -> &Range<T>

Source

fn as_legacy_range_mut(&mut self) -> &mut Range<T>

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<T> AsLegacyRange<T> for Range<T>

Source§

impl<T> AsLegacyRange<T> for RangeIter<T>