In one of my projects, I’m defining a struct that holds two vectors and want to define a view type over slices of each of the members, in the way that &[T]
is a view over Vec<T>
or &str
is a view over String
. Since the view type must contain two slice references, it can’t be expressed as a reference itself (so I can’t have &Thing
borrowing ThingBuf
, unless I’m missing something).
I want to have both immutable and mutable views over the resource (i.e. separate ThingRef
and ThingMut
types instead of &Thing
and &mut Thing
), and some of the methods I’m implementing return references (mutable in some cases) inside the resource being borrowed.
What are the best practices for implementing such types so that they can be used like built-in references as much as possible? Note that I’m using nightly Rust.
Edit: here’s a contrived example that shows what I’m trying to do.