Skip to content

Commit

Permalink
Use onlyerror to simplify example-full
Browse files Browse the repository at this point in the history
Fixes `cargo machete`
  • Loading branch information
parasyte committed Feb 10, 2024
1 parent eb109f5 commit 1db625a
Showing 1 changed file with 6 additions and 32 deletions.
38 changes: 6 additions & 32 deletions examples/full/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use error_iter::ErrorIter as _;
use onlyargs::{traits::*, CliError, OnlyArgs};
use onlyerror::Error;
use std::{ffi::OsString, fmt::Write as _, path::PathBuf, process::ExitCode};

#[derive(Debug)]
Expand Down Expand Up @@ -84,40 +85,13 @@ impl OnlyArgs for Args {
}
}

#[derive(Debug)]
#[derive(Debug, Error)]
enum Error {
Cli(CliError),
Io(std::io::Error),
}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Cli(_) => write!(f, "Argument parsing error"),
Self::Io(_) => write!(f, "I/O error"),
}
}
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Cli(err) => Some(err),
Self::Io(err) => Some(err),
}
}
}
/// Argument parsing error.
Cli(#[from] CliError),

impl From<CliError> for Error {
fn from(value: CliError) -> Self {
Self::Cli(value)
}
}

impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::Io(value)
}
/// I/O error.
Io(#[from] std::io::Error),
}

fn run() -> Result<(), Error> {
Expand Down

0 comments on commit 1db625a

Please sign in to comment.