Struct linotype::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
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.
Creates a new non-pinning OwnedProjection
instance.
FIXME:
This can nearly be
const
. It may be worthwhile to contribute a second constructor toArena
.
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.
Retrieves a reference to the first value associated with key
, iff available.
Retrieves a mutable reference to the first value associated with key
, iff available.
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,
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.
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,
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.
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)>,
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.
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>,
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
Auto Trait Implementations
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> where
K: UnwindSafe,
V: UnwindSafe + RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Pipes by value. This is generally the method you want to use. Read more
Borrows self
and passes that borrow into the pipe function. Read more
Mutably borrows self
and passes that borrow into the pipe function. Read more
Borrows self
, then passes self.borrow()
into the pipe function. Read more
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
Borrows self
, then passes self.as_ref()
into the pipe function.
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
Borrows self
, then passes self.deref()
into the pipe function.
Immutable access to the Borrow<B>
of a value. Read more
Mutable access to the BorrowMut<B>
of a value. Read more
Immutable access to the AsRef<R>
view of a value. Read more
Mutable access to the AsMut<R>
view of a value. Read more
Immutable access to the Deref::Target
of a value. Read more
Mutable access to the Deref::Target
of a value. Read more
Calls .tap()
only in debug builds, and is erased in release builds.
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_deref()
only in debug builds, and is erased in release
builds. Read more