Exotic Examples for Field Projections
This is a list of ideas that require more work on our proposal to integrate, these have not been fleshed out yet and might not make it into the final design. Nevertheless, they enable interesting use-cases and we’ll try to integrate them.
FileSlice<T> (Alice)
- Have a type
FileSlice<T>type that points at aT: FromBytesinside of a file with a file-offset that’su64.- Projections require that
P::Target: FromBytes(we already support this with awherebound on thePlaceBorrowimpl). - We also want to use
PlaceReadto perform aread_atcall and extract the contents of aT. But that call can not only fail, but also not read enough bytes, because the file is too short. Our currentPlaceRead::readfunction must return a<Self as HasPlace>::Target, which we want to beTforFileSlicein order to support projecting to subfields.
- Projections require that
- Needs to have custom projections that allow for
u64instead ofusizeoffsets.
HashMap<K, V> (Alice & Benno)
- With custom projections, we could allow
map["key"] = value;to meanmap.insert("key", value);. - Needs to have custom projections that allow for
&'static str(or anySizedvalue in general) instead ofusize. - We would also need to coordinate with
Index[Mut], since we’re now generalizing it too (maybe we need to do that already).