Skip to main content

Entry

Struct Entry 

Source
pub struct Entry<'a, 'rem, T> { /* private fields */ }
Expand description

Vec entry.

Entry allows you to remove, read or mutate the element behind it.

The only way to get this struct is to call Removing::next method.

§forget behavior

When Entry destructor (drop) is not runned (this can be achieved via mem::forget, ManuallyDrop, etc) the entry is not skiped and the next call to Removing::next returns the same entry.

use core::mem;
use vecrem::VecExt;

let mut vec = vec![1, 2, 3];
{
    let mut rem = vec.removing();

    let a = rem.next().unwrap();
    assert_eq!(a.value(), &1);
    mem::forget(a);

    let b = rem.next().unwrap();
    assert_eq!(b.value(), &1);
    mem::forget(b);
}
assert_eq!(vec, [1, 2, 3]);

Implementations§

Source§

impl<T> Entry<'_, '_, T>

Source

pub fn remove(self) -> T

Remove element behind this entry.

Source

pub fn value(&self) -> &T

Get access to the element behind this entry.

Source

pub fn value_mut(&mut self) -> &mut T

Get unique access to the element behind this entry.

Source

pub fn peek_next(&mut self) -> Option<&mut T>

Get unique access to the element after the element behind this entry.

Returns None if this entry corresponds to the last item in the vec.

Trait Implementations§

Source§

impl<T> Drop for Entry<'_, '_, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, 'rem, T> Freeze for Entry<'a, 'rem, T>

§

impl<'a, 'rem, T> RefUnwindSafe for Entry<'a, 'rem, T>
where T: RefUnwindSafe,

§

impl<'a, 'rem, T> Send for Entry<'a, 'rem, T>
where T: Send,

§

impl<'a, 'rem, T> Sync for Entry<'a, 'rem, T>
where T: Sync,

§

impl<'a, 'rem, T> Unpin for Entry<'a, 'rem, T>

§

impl<'a, 'rem, T> UnsafeUnpin for Entry<'a, 'rem, T>

§

impl<'a, 'rem, T> !UnwindSafe for Entry<'a, 'rem, T>

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.