这是indexloc提供的服务,不要输入任何密码
Skip to content

Every function that can fail should return an Option or Result #43

@maxbla

Description

@maxbla

There are several functions that can panic where it makes more sense to return a Option/Result. display_size() on windows/linux is an example. On Linux, it panics if it can't open the display or get the default screen. It could easily return an Option<(u64, u64)>, or even Result<(u64, u64), rdev::ToBeDeterminedError>.

The ToBeDeterminedError type is so named because I'm not fully sure of it's requirements yet. I think we should use one Error type across the entire crate, so that every fallible operation returns Result<T, ToBeDeterminedError> for some type T (we could make rdev::Result<T> a type alias for this, as std::io::Result does). ToBeDeterminedError should be platform agnostic - no X11NoDisplay errors, only NoDisplay errors. For example, it would include all variants of SimulateError, ListenError and NoDisplay error, and maybe some more later. It would also probably be marked with the #[non_exhaustive] attribute until rdev has a 1.0 release. How does this sound?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions