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

Remove ?Sized bounds or add CI test that they work #195

Open
ids1024 opened this issue Jan 27, 2024 · 3 comments
Open

Remove ?Sized bounds or add CI test that they work #195

ids1024 opened this issue Jan 27, 2024 · 3 comments

Comments

@ids1024
Copy link
Member

ids1024 commented Jan 27, 2024

#132 added trait bonds with ?Sized.

Context<dyn HasDisplayHandle> was mentioned there, but if you try to specify that type anywhere, it errors because Context and ContextDispatch do not have D: ?Sized bounds. So the public API doesn't actually allow that.

Adding those bounds is easy, but is there a way to construct a Context<dyn HasDisplayHandle>?

If ?Sized is useful, we should make sure it works and have a test that it continues working on all platforms. Otherwise, it can be removed, which may make other refactoring easier.

CC @notgull

@notgull
Copy link
Member

notgull commented Jan 28, 2024

Is there any explicit refactoring that doesn't work with ?Sized bounds?

I think it only works on Nightly, but there I think you can coerce an &Context<Window> to an &Context<dyn HasDisplayHandle>.

@ids1024
Copy link
Member Author

ids1024 commented Jan 28, 2024

I don't think it should be an issue with anything, but ?Sized may need to be added in more places, and some care may be needed not to break this use case, so if it's possible it would be good to have a test for it.

It's also possible to use Context<Box<dyn HasDisplayHandle>>, so the advantage is saving an extra boxing, I guess.

@ids1024
Copy link
Member Author

ids1024 commented Jan 28, 2024

I don't think Rust could allow a coercion from Context<T> to Context<dyn HasDisplayHandle<T>> since type type signature doesn't express exactly how the T is used.

I think if it's possible we'd at least need to provide some kind of conversion for that to work. And I don't know exactly how that works when we have a boxed/ref-counted custom unsized type containing the T.

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

No branches or pull requests

2 participants