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 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.

Creates a new non-pinning OwnedProjection instance.

FIXME:

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

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.

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.

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.

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.

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

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

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Performs the conversion.

Performs the conversion.

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.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

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

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Attempts to convert self into T using TryInto<T>. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.