Skip to main content

IteratorSpecImpl

Trait IteratorSpecImpl 

Source
pub trait IteratorSpecImpl: Iterator {
    // Required methods
    exec fn obeys_prophetic_iter_laws(&self) -> bool;
    exec fn remaining(&self) -> Seq<Self::Item>;
    exec fn produces(&self) -> Seq<bool>;
    exec fn decrease(&self) -> Option<nat>;
    exec fn peek(&self, index: int) -> Option<Self::Item>;
}

Required Methods§

Source

exec fn obeys_prophetic_iter_laws(&self) -> bool

This iterator obeys the specifications below on next, expressed in terms of prophetic spec functions. Only finite iterators (i.e., those that eventually return None and then continue to return None) or infinite iterators that never return None should use this interface.

Source

exec fn remaining(&self) -> Seq<Self::Item>

Sequence of all potentially returned items

Source

exec fn produces(&self) -> Seq<bool>

For each potential item in remaining(), does the item actually get returned, or does the iterator get “stuck” trying to produce it, e.g., because a client supplied a closure that diverges?

Source

exec fn decrease(&self) -> Option<nat>

Value used by default for the decreases clause when no explicit decreases clause is provided (the user can override this with an explicit decreases clause). If there’s no appropriate metric to decrease, this can return None, and the user will have to provide an explicit decreases clause.

Source

exec fn peek(&self, index: int) -> Option<Self::Item>

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<'a, K, V> IteratorSpecImpl for Iter<'a, K, V>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter(*self).len() {
        let (k, v) = into_iter(*self)[index];
        Some((&k, &v))
    } else {
        None
    }
}
Source§

impl<'a, K, V> IteratorSpecImpl for Iter<'a, K, V>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter(*self).len() {
        let (k, v) = into_iter(*self)[index];
        Some((&k, &v))
    } else {
        None
    }
}
Source§

impl<'a, K, V> IteratorSpecImpl for Keys<'a, K, V>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_keys(*self).len() {
        Some(&into_iter_keys(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a, K, V> IteratorSpecImpl for Keys<'a, K, V>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_keys(*self).len() {
        Some(&into_iter_keys(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a, K, V> IteratorSpecImpl for Values<'a, K, V>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_values(*self).len() {
        Some(&into_iter_values(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a, K, V> IteratorSpecImpl for Values<'a, K, V>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_values(*self).len() {
        Some(&into_iter_values(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a, K> IteratorSpecImpl for Iter<'a, K>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_hash_keys(*self).len() {
        Some(&into_iter_hash_keys(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a, T: 'a> IteratorSpecImpl for Chunks<'a, T>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < after_chunks_elts(*self).len() {
        Some(after_chunks_elts(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a, T: 'a> IteratorSpecImpl for Iter<'a, T>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_elts(*self).len() {
        Some(&into_iter_elts(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a, T: 'a> IteratorSpecImpl for Iter<'a, T>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_elts(*self).len() {
        Some(&into_iter_elts(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a, T: 'a> IteratorSpecImpl for IterMut<'a, T>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{ None }
Source§

impl<'a, T> IteratorSpecImpl for Iter<'a, T>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_btree_keys(*self).len() {
        Some(&into_iter_btree_keys(*self)[index])
    } else {
        None
    }
}
Source§

impl<'a> IteratorSpecImpl for Chars<'a>

Available on verus_keep_ghost and crate feature alloc only.
Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_elts(*self).len() {
        Some(into_iter_elts(*self)[index])
    } else {
        None
    }
}
Source§

impl<A, B> IteratorSpecImpl for Zip<A, B>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{
    &&& zip_iter_fst(*self).obeys_prophetic_iter_laws()
    &&& zip_iter_snd(*self).obeys_prophetic_iter_laws()

}
Source§

closed spec fn remaining(&self) -> Seq<Self::Item>

Source§

closed spec fn produces(&self) -> Seq<bool>

Source§

closed spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    match (zip_iter_fst(*self).peek(index), zip_iter_snd(*self).peek(index)) {
        (Some(a), Some(b)) => Some((a, b)),
        _ => None,
    }
}
Source§

impl<A: Step> IteratorSpecImpl for Range<A>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ obeys_range_step_spec::<A>() }
Source§

open spec fn remaining(&self) -> Seq<Self::Item>

{
    let steps = self.start.spec_steps_between_int(self.end);
    let len = if steps > 0 { steps } else { 0 };
    Seq::new(len as nat, |i: int| self.start.spec_forward_checked_int(i).unwrap())
}
Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

open spec fn decrease(&self) -> Option<nat>

{ Some(self.start.spec_steps_between_int(self.end) as nat) }
Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index <= self.start.spec_steps_between_int(self.end) {
        Some(self.start.spec_forward_checked_int(index).unwrap())
    } else {
        None
    }
}
Source§

impl<A: Step> IteratorSpecImpl for RangeInclusive<A>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ obeys_range_step_spec::<A>() }
Source§

open spec fn remaining(&self) -> Seq<Self::Item>

{
    Seq::new(
        spec_range_inclusive_len(self),
        |i: int| self@.start.spec_forward_checked_int(i).unwrap(),
    )
}
Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

open spec fn decrease(&self) -> Option<nat>

{ Some(spec_range_inclusive_len(self)) }
Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index <= spec_range_inclusive_len(self) {
        Some(self@.start.spec_forward_checked_int(index).unwrap())
    } else {
        None
    }
}
Source§

impl<B, I, F> IteratorSpecImpl for Map<I, F>
where I: Iterator + IteratorSpec, F: FnMut(I::Item) -> B,

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ map_iter(*self).obeys_prophetic_iter_laws() }
Source§

uninterp spec fn remaining(&self) -> Seq<B>

Source§

uninterp spec fn produces(&self) -> Seq<bool>

Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<B>

{
    match map_iter(*self).peek(index) {
        Some(v) => {
            let x = choose |x| map_fun(*self).ensures((v,), x);
            Some(x)
        }
        None => None,
    }
}
Source§

impl<I, P> IteratorSpecImpl for Filter<I, P>
where I: Iterator + IteratorSpec, P: FnMut(&I::Item) -> bool,

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ filter_iter(*self).obeys_prophetic_iter_laws() }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

uninterp spec fn produces(&self) -> Seq<bool>

Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{ None }
Source§

impl<I> IteratorSpecImpl for &mut I
where I: Iterator,

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ <I as IteratorSpec>::obeys_prophetic_iter_laws(*self) }
Source§

open spec fn remaining(&self) -> Seq<Self::Item>

{ <I as IteratorSpec>::remaining(*self) }
Source§

open spec fn produces(&self) -> Seq<bool>

{ <I as IteratorSpec>::produces(*self) }
Source§

open spec fn decrease(&self) -> Option<nat>

{ <I as IteratorSpec>::decrease(*self) }
Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{ <I as IteratorSpec>::peek(*self, index) }
Source§

impl<I> IteratorSpecImpl for Rev<I>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ rev_iter(*self).obeys_prophetic_iter_laws() }
Source§

closed spec fn remaining(&self) -> Seq<Self::Item>

Source§

closed spec fn produces(&self) -> Seq<bool>

Source§

closed spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{ rev_iter(*self).peek_back(index) }
Source§

impl<I> IteratorSpecImpl for Skip<I>
where I: Iterator,

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ skip_iter(*self).obeys_prophetic_iter_laws() }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

uninterp spec fn produces(&self) -> Seq<bool>

Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{ skip_iter(*self).peek(skip_init_n(*self) + index) }
Source§

impl<I> IteratorSpecImpl for Take<I>
where I: Iterator,

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ take_iter(*self).obeys_prophetic_iter_laws() }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

uninterp spec fn produces(&self) -> Seq<bool>

Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{ take_iter(*self).peek(index) }
Source§

impl<K, V, A: Allocator> IteratorSpecImpl for IntoIter<K, V, A>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_entries(*self).len() {
        Some(into_iter_entries(*self)[index])
    } else {
        None
    }
}
Source§

impl<T, A: Allocator> IteratorSpecImpl for IntoIter<T, A>

Source§

open spec fn obeys_prophetic_iter_laws(&self) -> bool

{ true }
Source§

uninterp spec fn remaining(&self) -> Seq<Self::Item>

Source§

open spec fn produces(&self) -> Seq<bool>

{ Seq::new(IteratorSpec::remaining(self).len(), |i: int| true) }
Source§

uninterp spec fn decrease(&self) -> Option<nat>

Source§

open spec fn peek(&self, index: int) -> Option<Self::Item>

{
    if 0 <= index < into_iter_elts(*self).len() {
        Some(into_iter_elts(*self)[index])
    } else {
        None
    }
}

Implementors§