softbuffer icon indicating copy to clipboard operation
softbuffer copied to clipboard

Remove ?Sized bounds or add CI test that they work

Open ids1024 opened this issue 1 year ago • 3 comments

https://github.com/rust-windowing/softbuffer/pull/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

ids1024 avatar Jan 27 '24 21:01 ids1024

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>.

notgull avatar Jan 28 '24 00:01 notgull

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 avatar Jan 28 '24 00:01 ids1024

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.

ids1024 avatar Jan 28 '24 00:01 ids1024