PIterator

Struct PIterator 

Source
pub struct PIterator<K, V>
where K: Debug, V: Debug,
{ /* private fields */ }
Expand description

An effort to emulate a C++ std::map iterator in Rust. It will have functionality like: prev(), next(), get(), erase(), lower_bound(), replace_key()

Implementations§

Source§

impl<K, V> PIterator<K, V>
where K: Clone + Debug + Unpin + Ord + PartialOrd, V: Clone + Debug + Unpin,

Source

pub fn new(list: Rc<RefCell<LinkedList<K, V>>>) -> Result<Self, MapError>

Initiates the pointer with a list, set current to the head of the list.

Source

pub fn new_2(list: Rc<RefCell<LinkedList<K, V>>>, current: usize) -> Self

Initiates the pointer with a list, set index.

Source

pub fn get_k(&self) -> Result<K, MapError>

Returns a clone of the key at current position

Source

pub fn get_v(&self) -> Result<V, MapError>

Returns a clone of the value at current position

Source

pub fn next(&mut self) -> Result<(), MapError>

Move to the next element. Note that this is NOT a Rust iterator next() method. Always check validity of the iterator with is_ok() after next()

Source

pub fn prev(&mut self) -> Result<(), MapError>

Move to the previous element Always check validity of the iterator with is_ok() after prev()

Source

pub fn move_to_head(&mut self) -> Result<(), MapError>

Move to the first element

Source

pub fn move_to_tail(&mut self) -> Result<(), MapError>

Move to the last element

Source

pub fn is_ok(&self) -> Result<bool, MapError>

Return true if pointer has NOT moved past beginning or end of the list

Source

pub fn is_at_head(&self) -> Result<bool, MapError>

Return true if pointer is at head position or if the list is empty

Source

pub fn is_at_tail(&self) -> Result<bool, MapError>

Return true if pointer is at tail position or if the list is empty

Source

pub fn replace_key(&mut self, key: K) -> Result<(), MapError>

Replace current key. This will destroy the internal order of element if you replace an element with something out of order.

Source

pub fn current(&self) -> usize

returns current index

Source

pub fn remove_current(&mut self) -> Result<(K, V), MapError>

Remove the current element and return it. Move current to the old prev value if exist. Else pick old next index. Note: make sure that there are no other Pointer objects at this position.

Source

pub fn lower_bound( list: Rc<RefCell<LinkedList<K, V>>>, key: K, ) -> Result<Self, MapError>

Returns a new Pointer positioned at the lower bound item. Lower bound item is the first element in the container whose key is not considered to go before position (i.e., either it is equivalent or goes after). Returns a Pointer where is_ok() returns false if no data is found

Trait Implementations§

Source§

impl<K, V> Clone for PIterator<K, V>
where K: Debug + Unpin + Ord + PartialOrd, V: Debug + Unpin,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V> Debug for PIterator<K, V>
where K: Debug + Unpin + Ord + PartialOrd, V: Debug + Unpin,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for PIterator<K, V>

§

impl<K, V> !RefUnwindSafe for PIterator<K, V>

§

impl<K, V> !Send for PIterator<K, V>

§

impl<K, V> !Sync for PIterator<K, V>

§

impl<K, V> Unpin for PIterator<K, V>

§

impl<K, V> !UnwindSafe for PIterator<K, V>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.