Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ?Sized/unsizing coercions #74

Closed
SoniEx2 opened this issue Oct 13, 2022 · 4 comments
Closed

Support ?Sized/unsizing coercions #74

SoniEx2 opened this issue Oct 13, 2022 · 4 comments

Comments

@SoniEx2
Copy link

SoniEx2 commented Oct 13, 2022

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 SoniEx2 changed the title Support ?Sized Support ?Sized Oct 13, 2022
@SoniEx2 SoniEx2 changed the title Support ?Sized Support ?Sized/unsizing coercions Oct 13, 2022
@steffahn
Copy link
Contributor

steffahn commented Jan 8, 2023

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.

@SoniEx2
Copy link
Author

SoniEx2 commented Jan 8, 2023

well, selfref can do it.

@SoniEx2
Copy link
Author

SoniEx2 commented Jan 11, 2025

will it ever be possible to do an unsizing/trait object coercion on an ouroboros object or can we say selfref is the best crate for this stuff?

@someguynamedjosh
Copy link
Owner

AFAIK, for this specific feature, selfref is currently the only crate that allows it (without just using custom unsafe code.) I don't see a way to add support for this without making significant sacrifices in terms of ergonomics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants