Struct OwnedProjection

Source
pub struct OwnedProjection<K, V> { /* private fields */ }
Expand description

A lingering projection/keyed sequence reprojector.

This type acts as stable multi-map from items in the input sequence (or rather: derived stored keys) to mutable stored values.

Stored keys and values persist across reprojections, as long as the necessary items appear in each sequence to warrant it.

An OwnedProjection can be converted into a value-pinning version of itself by through its .pin(self) method.
This pinning variant is still mutable, but won’t release stored values by value, always dropping them in place instead.

Implementations§

Source§

impl<K, V> OwnedProjection<K, V>

§Generics Glossary

  • 'a: Lifetime of the OwnedProjection.
  • 'b: Lifetime of the in-progress reprojection (i.e. the returned iterator).
  • K: (Stored) Key.
  • V: (Stored) Value.
  • T: (Examined) Item.
  • Q: ?Sized: Query or Quality, borrowed from T.
  • S: Selector, projects (&mut T) -> &Q.
  • F: Factory, projects (&mut T, &K) -> V.
  • I: Input Iterator, with varying Iterator::Item.
  • E: Arbitrary payload for Result::Err.

The selector will generally run once per item, the factory only to generate one value for each new entry.

The quality must be Eq to prevent edge cases where values cannot be kept, and stored keys are derived from the quality using ToOwned as necessary.

Note that in the resulting (T, &mut V) (i.e. just-confirmed item-value entries), the T is by value and the V is valid for the entirety of 'b.

§Implementation Notes

This currently uses at least

K: Borrow<Q>,
T: 'b,
Q: ?Sized + Eq + ToOwned<Owned = K>,
S: 'b + FnOnce(&mut T) -> Result<Qr, E>,
F: 'b + FnOnce(&mut T, &K) -> Result<V, E>,

instead of

K: Borrow<Qr::Target>,
T: 'b,
Qr: Deref,
Qr::Target: ?Sized + Eq + ToOwned<Owned = K>,
S: 'b + FnOnce(&mut T) -> Result<Qr, E>,
F: 'b + FnOnce(&mut T, &K) -> Result<V, E>,

because the latter has the compiler ask for lifetime bounds on Qr, or a duplicate implementation entirely.

A Q: 'b bound is present on most methods, but usually not a problem.

Source

pub fn new() -> Self

Creates a new non-pinning OwnedProjection instance.

FIXME:

This can nearly be const. It may be worthwhile to contribute a second constructor to Arena.

Source

pub const fn pin(self) -> Pin<Self>

Turns this OwnedProjection into a Pin of its values.

Note that a panic in a K or V Drop implementation will abort the process via double-panic unless the "std" feature is enabled, as long as this instance remains pinning.

With the "std" feature enabled, OwnedProjection will always continue to clean up as needed, then re-panic the first panic it encountered.

§Safety Notes

Note that this sets a flag to abort on panics from key and value Drop implementations iff the "std" feature is not active.

This means that transmuting an OwnedProjection to wrap it in a Pin is normally not a sound operation.
However, OwnedProjection itself never relies on this flag in other circumstances.

§See also

PinningOwnedProjection, for the pinning API.

Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: ?Sized + Eq,

Retrieves a reference to the first value associated with key, iff available.

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: ?Sized + Eq,

Retrieves a mutable reference to the first value associated with key, iff available.

Source

pub fn reproject_try_by_keyed_try_with_keyed<'a: 'b, 'b, T, Q, S, F, I, E>( &'a mut self, items_selectors_factories: I, ) -> impl 'b + Iterator<Item = Result<(T, &'a mut V), E>>
where K: Borrow<Q>, T: 'b, Q: ?Sized + Eq + ToOwned<Owned = K>, S: 'b + FnOnce(&mut T) -> Result<&Q, E>, F: 'b + FnOnce(&mut T, &K) -> Result<V, E>, I: 'b + IntoIterator<Item = (T, S, F)>, E: 'b,

Lazily updates this map according to a sequence of item, fallible selector and fallible factory triples.

Values that aren’t reused are dropped together with the returned iterator or on the next .reproject… method call.

Source

pub fn reproject_try_by_try_with<'a: 'b, 'b, T, Q, S, F, I, E>( &'a mut self, items: I, selector: S, factory: F, ) -> impl 'b + Iterator<Item = Result<(T, &'a mut V), E>>
where K: Borrow<Q>, T: 'b, Q: 'b + ?Sized + Eq + ToOwned<Owned = K>, S: 'b + FnMut(&mut T) -> Result<&Q, E>, F: 'b + FnMut(&mut T, &K) -> Result<V, E>, I: 'b + IntoIterator<Item = T>, E: 'b,

Lazily updates this map according to a sequence of items, a fallible selector and fallible factory.

Values that aren’t reused are dropped together with the returned iterator or on the next .reproject… method call.

Source

pub fn reproject_by_keyed_with_keyed<'a: 'b, 'b, T, Q, S, F, I>( &'a mut self, items_selectors_factories: I, ) -> impl 'b + Iterator<Item = (T, &'a mut V)>
where K: Borrow<Q>, T: 'b, Q: 'b + ?Sized + Eq + ToOwned<Owned = K>, S: 'b + FnOnce(&mut T) -> &Q, F: 'b + FnOnce(&mut T, &K) -> V, I: 'b + IntoIterator<Item = (T, S, F)>,

Lazily updates this map according to a sequence of item, selector and factory triples.

Values that aren’t reused are dropped together with the returned iterator or on the next .reproject… method call.

Source

pub fn reproject_by_with<'a: 'b, 'b, T, Q, S, F, I>( &'a mut self, items: I, selector: S, factory: F, ) -> impl 'b + Iterator<Item = (T, &'a mut V)>
where K: Borrow<Q>, T: 'b, Q: 'b + ?Sized + Eq + ToOwned<Owned = K>, S: 'b + FnMut(&mut T) -> &Q, F: 'b + FnMut(&mut T, &K) -> V, I: 'b + IntoIterator<Item = T>,

Lazily updates this map according to a sequence of items, a selector and a factory.

Values that aren’t reused are dropped together with the returned iterator or on the next .reproject… method call.

Trait Implementations§

Source§

impl<K, V> Default for OwnedProjection<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V> Drop for OwnedProjection<K, V>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<K, V> PinningOwnedProjection for Pin<OwnedProjection<K, V>>

Source§

type K = K

The type of stored keys.
Source§

type V = V

The type of values.
Source§

fn unpin(self) -> OwnedProjection<K, V>
where V: Unpin,

Converts this instance back into a non-pinning OwnedProjection<K, V>. Read more
Source§

fn get<Q>(&self, key: &Q) -> Option<Pin<&V>>
where K: Borrow<Q>, Q: ?Sized + Eq,

Retrieves a reference to the first value associated with key, iff available.
Source§

fn get_mut<Q>(&mut self, key: &Q) -> Option<Pin<&mut V>>
where K: Borrow<Q>, Q: ?Sized + Eq,

Retrieves a mutable reference to the first value associated with key, iff available.
Source§

fn reproject_try_by_keyed_try_with_keyed<'a: 'b, 'b, T, Q, S, F, I, E>( &'a mut self, items_selectors_factories: I, ) -> Box<dyn Iterator<Item = Result<(T, Pin<&'a mut V>), E>> + 'b>
where K: Borrow<Q>, T: 'b, Q: 'b + ?Sized + Eq + ToOwned<Owned = K>, S: 'b + FnOnce(&mut T) -> Result<&Q, E>, F: 'b + FnOnce(&mut T, &K) -> Result<V, E>, I: 'b + IntoIterator<Item = (T, S, F)>, E: 'b,

Lazily updates this map according to a sequence of item, fallible selector and fallible factory triples. Read more
Source§

fn reproject_try_by_try_with<'a: 'b, 'b, T, Q, S, F, I, E>( &'a mut self, items: I, selector: S, factory: F, ) -> Box<dyn Iterator<Item = Result<(T, Pin<&'a mut V>), E>> + 'b>
where K: Borrow<Q>, T: 'b, Q: 'b + ?Sized + Eq + ToOwned<Owned = K>, S: 'b + FnMut(&mut T) -> Result<&Q, E>, F: 'b + FnMut(&mut T, &K) -> Result<V, E>, I: 'b + IntoIterator<Item = T>, E: 'b,

Lazily updates this map according to a sequence of items, a fallible selector and fallible factory. Read more
Source§

fn reproject_by_keyed_with_keyed<'a: 'b, 'b, T, Q, S, F, I>( &'a mut self, items_selectors_factories: I, ) -> Box<dyn Iterator<Item = (T, Pin<&'a mut V>)> + 'b>
where K: Borrow<Q>, T: 'b, Q: 'b + ?Sized + Eq + ToOwned<Owned = K>, S: 'b + FnOnce(&mut T) -> &Q, F: 'b + FnOnce(&mut T, &K) -> V, I: 'b + IntoIterator<Item = (T, S, F)>,

Lazily updates this map according to a sequence of item, selector and factory triples. Read more
Source§

fn reproject_by_with<'a: 'b, 'b, T, Q, S, F, I>( &'a mut self, items: I, selector: S, factory: F, ) -> Box<dyn Iterator<Item = (T, Pin<&'a mut V>)> + 'b>
where K: Borrow<Q>, T: 'b, Q: 'b + ?Sized + Eq + ToOwned<Owned = K>, S: 'b + FnMut(&mut T) -> &Q, F: 'b + FnMut(&mut T, &K) -> V, I: 'b + IntoIterator<Item = T>,

Lazily updates this map according to a sequence of items, a selector and a factory. Read more

Auto Trait Implementations§

§

impl<K, V> !Freeze for OwnedProjection<K, V>

§

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

§

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

§

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

§

impl<K, V> Unpin for OwnedProjection<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for OwnedProjection<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> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. 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> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. 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.