Sashay contains type-erased and life-time erased types that mimic both regular Rust references and slices.
&T
-> AnyRef
&mut T
-> AnyMut
*const/mut T
-> AnyPtr
&[T]
-> AnySliceRef
&mut [T]
-> AnySliceMut
*const/mut [T]
-> AnySlicePtr
Any of these refs and muts can be constructed by calling ::erase()
on a reference/slice. The lifetime is still stored on the object, as well as the TypeId
, which is used to check if any downcast is valid.
The advantage of the slice types over using the regular ref types to [T]
is that the AnySlice*
types retain the slice length without having to downcast.
As far as I know the library is sound and passed cargo miri test
, but outside of personal use it is untested, not used in production code (yet?) and has not been audited. If you have constructive feedback, that is much appreciated.
```rust
let data : [i32; 3] = [0, 1, 2];
let any = sashay::AnySliceRef::erase(data.asslice());
let slice = any.downcastref::
asserteq!(slice, data.asslice()); ```