How to implement multiple unsize coercions?

I have a struct which has 2 pointer field, and I want to make unsize coercion on both of them. I have tried several methods but can't make it to work. See playground for a demo.

struct A<B:?Sized, C:?Sized> {
    b: *const B,
    c: *const C,

I want a way to control the unsize coersion manually, so I can coerce A<B, C> to A<UB, C>, A<B, UC> or A<UB, UC> by calling different method, where B: Unsize<UB>, C:Unsize<UC>.

If it is not possible, then is an auto unsize coersion from A<B, C> to A<UB, UC> possible? How?

Thanks for any help!

FIY, this works. You can define variants to selectively unsize coerce any field or fields.

impl<B:?Sized,C:?Sized> A<B,C>{
    fn unsize_both<U:?Sized,V:?Sized>(self)->A<U,V>
        where B:Unsize<U>,C:Unsize<V>
        let A{b,c} = self;

This method doesn't work if A implements Drop and its fields doesn't implement Copy and Clone.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.