ouroboros icon indicating copy to clipboard operation
ouroboros copied to clipboard

Support `?Sized`/unsizing coercions

Open SoniEx2 opened this issue 3 years ago • 2 comments

For feature-parity with selfref.

// cannot work, ?Sized must come last
#[self_referencing]
struct Foo<T: ?Sized> {
    x: T,
    #[borrows(x)]
    y: &'this dyn std::fmt::Debug,
}

// doesn't work, borrowees must come first
#[self_referencing]
struct Foo<T: ?Sized> {
    #[borrows(x)]
    y: &'this dyn std::fmt::Debug,
    x: T,
}

SoniEx2 avatar Oct 13 '22 20:10 SoniEx2

I cannot quite follow what’s the requested feature here. If you’re thinking of &Foo<[u8; N]> to &Foo<[u8]> coercions or the like, you’re probably missing the fact that all borrowed fields in an ouroboros self-referencing struct are implicitly put into a Box. So either way, x would need to become Box<T> which kills the unsizing due to the level of indirection, no matter the field order.

steffahn avatar Jan 08 '23 07:01 steffahn

well, selfref can do it.

SoniEx2 avatar Jan 08 '23 12:01 SoniEx2