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 onlyerror to simplify example-full #19

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading