rust-windowing / raw-window-handle

A common windowing interoperability library for Rust
Apache License 2.0
314 stars 49 forks source link

Type-system relationship between `HasRaw*Handle` and `Has*Handle` traits #135

Closed madsmtm closed 1 year ago

madsmtm commented 1 year ago

Should there be a type-system relationship between these?

I think it would make sense to make the normal handles subtraits of the raw handles, i.e. trait HasWindowHandle: HasRawWindowHandle { ... }?

Or maybe we should do a blanket impl<T: HasWindowHandle> for HasRawWindowHandle {}, or vice-versa?

madsmtm commented 1 year ago

Related: What is the value even in having two traits? Is it just that way because we're yet unsure of the design?

I think it'd make sense to combine them into a single HasWindowHandle/HasDisplayHandle trait.

notgull commented 1 year ago

This change would make the semver trick hard to do... but #136 would already make it impossible so why not just go full ham?

I've often compared the difference between HasRawWindowHandle and HasWindowHandle to the difference between AsRawFd and AsFd in the standard library. However, I struggle to think of a use case where a type would implement HasRawWindowHandle and not HasWindowHandle. The standard library has to keep AsRawFd forever to avoid a breaking change, but we don't.

I would be in favor of just merging the traits.

madsmtm commented 1 year ago

I think the semver trick is basically already impossible, see https://github.com/rust-windowing/raw-window-handle/issues/125#issuecomment-1605655931.