Closed diwic closed 7 years ago
Directly erasing the owner like this is not really doable with the memory layout of OwningRef, and looking at that ARef PR handling this by completely transmuting away the underlying type seems like a too error prone solution.
However, it should be possible to just add another layer of indirection, by creating a OwningRef of Box<Box<[u8]>>
, Box<Rc<[u8]>>
, Box<Ref<[u8]>>
, etc. Those can all be erased to the common Box<Erased>
.
I added some new methods for mapping the owner like this.
Oh, since I didn't get a reply in a timely fashion, I went ahead and created my own crate instead. Here's my ARef.
This might be more of a question than an issue, but...
Suppose I'm writing a function from which I want to return a
Vec<OwningRef<_, &[u8]>>
. Some of these slices areBox<[u8]>
, others areRc<[u8]>
, and some are perhapsRef<[u8]>
. So when the caller of the function drops thatVec<OwningRef<_, &[u8]>>
, theBox<[u8]>
s will be deallocated, theRc<[u8]>
s will have their refcount decreased, and theRef<[u8]>
s will have their read count decreased.Is this possible using the
Erased
functionality? It seems like erasing aOwningRef<Box<[u8]>, [u8]>
will give you aOwningRef<Box<Erased>, [u8]>
, where I'm actually is looking for aOwningRef<Erased, [u8]>
so I can abstract over several types of smart pointers.