Struct BacktrackingRecorder

Source
pub struct BacktrackingRecorder<Iter>
where Iter: Iterator,
{ /* private fields */ }
Expand description

A wrapper around an existing iterator to give it a historical representation with the ability to then produce copying and referencing backtracking iterators on the history

Implementations§

Source§

impl<Iter> BacktrackingRecorder<Iter>
where Iter: Iterator,

Source

pub fn new(iterator: Iter) -> Self

Create a BacktrackingRecorder from an existing iterator.

Source

pub fn referencing<'record>( &'record mut self, ) -> ReferencingBacktrackingIterator<'record, Iter>

Source

pub fn copying<'record>( &'record mut self, ) -> CopyingBacktrackingIterator<'record, Iter>
where Iter::Item: Clone,

Source

pub fn drain_history(&mut self) -> Vec<Iter::Item>

Take all items out of the history.

extern crate backtracking_iterator;
use backtracking_iterator::{BacktrackingIterator, BacktrackingRecorder};

let vec_iter = vec![1_u8, 2, 3].into_iter();
let mut rec = BacktrackingRecorder::new(vec_iter);

{
  let mut bt_ref = rec.referencing();
  bt_ref.next(); // 1_u8
}

let mut history = rec.drain_history().into_iter();
// Repeats only what was in the history
assert!(history.next().unwrap() == 1_u8);
assert!(history.next().is_none());

Trait Implementations§

Source§

impl<Iter, Item> IntoIterator for BacktrackingRecorder<Iter>
where Iter: Iterator<Item = Item> + IntoIterator<Item = Item>,

Source§

fn into_iter(self) -> Self::IntoIter

Destroy the record and return an iterator which starts from the beginning of the history and chains into the originally-given iterator

extern crate backtracking_iterator;
use backtracking_iterator::{BacktrackingIterator, BacktrackingRecorder};

let vec_iter = vec![1_u8, 2, 3].into_iter();
let mut rec = BacktrackingRecorder::new(vec_iter);

{
  let mut bt_ref = rec.referencing();
  bt_ref.next(); // 1_u8
}

let mut rec_iter = rec.into_iter();
// Repeats the value in the history
assert!(rec_iter.next().unwrap() == 1_u8);
// And follows up with the ones not yet recorded
assert!(rec_iter.next().unwrap() == 2_u8);
assert!(rec_iter.next().unwrap() == 3_u8);
assert!(rec_iter.next().is_none());
Source§

type Item = Item

The type of the elements being iterated over.
Source§

type IntoIter = Chain<IntoIter<Item>, <Iter as IntoIterator>::IntoIter>

Which kind of iterator are we turning this into?
Source§

impl<Iter> Record for BacktrackingRecorder<Iter>
where Iter: Iterator,

Source§

type RefPoint = usize

The type used to refer to positions in the history
Source§

fn get_ref_point(&self) -> usize

Yield a reference to the current point in the history This reference must be valid for as long as the current point remains in the history
Source§

fn forget_before(&mut self, position: usize)

Eliminate all the values before the given reference point from the history
Source§

fn forget(&mut self)

Forget all the values before the current position in the iterator Read more

Auto Trait Implementations§

§

impl<Iter> Freeze for BacktrackingRecorder<Iter>
where Iter: Freeze,

§

impl<Iter> RefUnwindSafe for BacktrackingRecorder<Iter>
where Iter: RefUnwindSafe, <Iter as Iterator>::Item: RefUnwindSafe,

§

impl<Iter> Send for BacktrackingRecorder<Iter>
where Iter: Send, <Iter as Iterator>::Item: Send,

§

impl<Iter> Sync for BacktrackingRecorder<Iter>
where Iter: Sync, <Iter as Iterator>::Item: Sync,

§

impl<Iter> Unpin for BacktrackingRecorder<Iter>
where Iter: Unpin, <Iter as Iterator>::Item: Unpin,

§

impl<Iter> UnwindSafe for BacktrackingRecorder<Iter>
where Iter: UnwindSafe, <Iter as Iterator>::Item: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.