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
.
impl<K, V> OwnedProjection<K, V>
§Generics Glossary
'a
: Lifetime of theOwnedProjection
.'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 fromT
.S
: Selector, projects(&mut T) -> &Q
.F
: Factory, projects(&mut T, &K) -> V
.I
: Input Iterator, with varyingIterator::Item
.E
: Arbitrary payload forResult::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.
Sourcepub fn new() -> Self
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 toArena
.
Sourcepub const fn pin(self) -> Pin<Self>
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.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Retrieves a reference to the first value associated with key
, iff available.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Retrieves a mutable reference to the first value associated with key
, iff available.
Sourcepub 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>>
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>>
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.
Sourcepub 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>>
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>>
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.
Sourcepub 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)>
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)>
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.
Sourcepub 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)>
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)>
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>
impl<K, V> Default for OwnedProjection<K, V>
Source§impl<K, V> Drop for OwnedProjection<K, V>
impl<K, V> Drop for OwnedProjection<K, V>
Source§impl<K, V> PinningOwnedProjection for Pin<OwnedProjection<K, V>>
impl<K, V> PinningOwnedProjection for Pin<OwnedProjection<K, V>>
Source§fn unpin(self) -> OwnedProjection<K, V>where
V: Unpin,
fn unpin(self) -> OwnedProjection<K, V>where
V: Unpin,
OwnedProjection<K, V>
. Read moreSource§fn get<Q>(&self, key: &Q) -> Option<Pin<&V>>
fn get<Q>(&self, key: &Q) -> Option<Pin<&V>>
key
, iff available.Source§fn get_mut<Q>(&mut self, key: &Q) -> Option<Pin<&mut V>>
fn get_mut<Q>(&mut self, key: &Q) -> Option<Pin<&mut V>>
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>
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>
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>
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>
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>
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>
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>
impl<K, V> UnwindSafe for OwnedProjection<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
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
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
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
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.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
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.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
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.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
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.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
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.