Skip to content

Commit

Permalink
Further error type tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
segevfiner committed Feb 7, 2024
1 parent b22631d commit 0d3a37e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! # Examples
//!
//! ```
//! # fn try_main() -> Result<(), keepawake::Error> {
//! # fn try_main() -> keepawake::Result<()> {
//! let _awake = keepawake::Builder::default()
//! .display(true)
//! .reason("Video playback")
Expand All @@ -16,7 +16,7 @@
//! ```
//!
//! ```
//! # fn try_main() -> Result<(), keepawake::Error> {
//! # fn try_main() -> keepawake::Result<()> {
//! let _awake = keepawake::Builder::default()
//! .display(true)
//! .idle(true)
Expand All @@ -35,15 +35,22 @@ mod sys;
#[cfg(feature = "capi")]
pub mod capi;

/// A system error whose actual type varies by target.
pub use sys::Error as SystemError;

/// Error type.
#[derive(Error, Debug)]
pub enum Error {
#[error("builder: {0}")]
Builder(#[from] BuilderError),

#[error("system: {0}")]
System(#[from] sys::Error),
System(#[from] SystemError),
}

/// A specialized [`Result`](std::result::Result) type for this crate.
pub type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Builder, Debug)]
#[builder(public, name = "Builder", build_fn(private))]
#[allow(dead_code)] // Some fields are unused on some platforms
Expand Down Expand Up @@ -79,7 +86,7 @@ struct Options {

impl Builder {
/// Create the [`KeepAwake`].
pub fn create(&self) -> Result<KeepAwake, Error> {
pub fn create(&self) -> Result<KeepAwake> {
Ok(KeepAwake {
_imp: sys::KeepAwake::new(self.build()?)?,
})
Expand Down

0 comments on commit 0d3a37e

Please sign in to comment.