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

Use std::io::Error for error results, except get_planar_framebuffer #179

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

ids1024
Copy link
Member

@ids1024 ids1024 commented Nov 7, 2023

Based on discussion on #173. Which this supersedes.

All functions in drm and drm_ffi returning SystemError, except get_planar_frambuffer, only use it for representing standard Unix error kinds. So std::io::Error can be used instead.

For get_planar_framebuffer, a GetPlanarFramebufferError error is defined. It might be nice if Rust has anonymous sum types for this sort of thing, but this seems like the typical pattern. And better than using the same error kind everywhere if UnrecognizedFourcc isn't possible in any other function.

This should remove nix from the public API of the crate. This makes errors a bit simpler to handle for users of the library using rustix or a different version of nix, and allows drm to change which it uses without a breaking API change.

Testing this in Smithay (Smithay/smithay@master...ids1024:smithay:drm-rs-update), the section where it was matching on several variants of SystemError is simplified, and other things aren't changed much. Using io::Error in a variant did however mean removing Clone and Copy from drm_lease::Error. But those shouldn't really be needed for an error kind generally.

(Softbuffer is also trivial to update. cosmic-comp required no changes with the patched Smithay above. I'm not familiar with other users of drm-rs.)

In some ways the Errno types from nix or rustix would be better, but it's best not to have a public dependency on that or duplicate it.

Based on discussion on Smithay#173. Which
this supersedes.

All functions in `drm` and `drm_ffi` returning `SystemError`, except
`get_planar_frambuffer`, only use it for representing standard Unix
error kinds. So `std::io::Error` can be used instead.

For `get_planar_framebuffer`, a `GetPlanarFramebufferError` error is
defined. It might be nice if Rust has anonymous sum types for this sort
of thing, but this seems like the typical pattern. And better than using
the same error kind everywhere if `UnrecognizedFourcc` isn't possible in
any other function.

This should remove `nix` from the public API of the crate. This makes
errors a bit simpler to handle for users of the library using `rustix`
or a different version of `nix`, and allows `drm` to change which it
uses without a breaking API change.
@Drakulix Drakulix merged commit ba7d0d7 into Smithay:develop Nov 7, 2023
16 checks passed
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

Successfully merging this pull request may close these issues.

2 participants