Fmt + Clippy
parent
59351fb699
commit
6407335362
|
@ -1,16 +1,15 @@
|
|||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use crate::parser::ByteArrayParseErr;
|
||||
use crate::formatter::format::FormatError;
|
||||
use crate::formatter::FormatConfigError;
|
||||
use crate::parser::ByteArrayParseErr;
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FormatyError {
|
||||
ByteArrayParseError(ByteArrayParseErr),
|
||||
FormatError(FormatError),
|
||||
FormatConfigError(FormatConfigError),
|
||||
FormatNotFound(String)
|
||||
|
||||
FormatNotFound(String),
|
||||
}
|
||||
|
||||
impl From<ByteArrayParseErr> for FormatyError {
|
||||
|
@ -37,11 +36,11 @@ impl Display for FormatyError {
|
|||
FormatyError::ByteArrayParseError(e) => e.to_string(),
|
||||
FormatyError::FormatError(e) => e.to_string(),
|
||||
FormatyError::FormatConfigError(e) => e.to_string(),
|
||||
FormatyError::FormatNotFound(err_msg) => format!("'{}' config not found.", err_msg)
|
||||
FormatyError::FormatNotFound(err_msg) => format!("'{}' config not found.", err_msg),
|
||||
};
|
||||
|
||||
write!(f, "{}", err_msg)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for FormatyError {}
|
||||
impl Error for FormatyError {}
|
||||
|
|
|
@ -2,21 +2,21 @@ pub mod format;
|
|||
mod printers;
|
||||
|
||||
use crate::formatter::format::Format;
|
||||
use rust_embed::RustEmbed;
|
||||
use serde::Deserialize;
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use rust_embed::RustEmbed;
|
||||
use std::str;
|
||||
use std::str::Utf8Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub enum FormatConfigError {
|
||||
IOError(std::io::Error),
|
||||
TomlError(toml::de::Error),
|
||||
Utf8Error(Utf8Error)
|
||||
Utf8Error(std::str::Utf8Error),
|
||||
}
|
||||
|
||||
impl Error for FormatConfigError {}
|
||||
|
@ -33,8 +33,8 @@ impl From<toml::de::Error> for FormatConfigError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Utf8Error> for FormatConfigError {
|
||||
fn from(e: Utf8Error) -> Self {
|
||||
impl From<std::str::Utf8Error> for FormatConfigError {
|
||||
fn from(e: std::str::Utf8Error) -> Self {
|
||||
Self::Utf8Error(e)
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ impl Display for FormatConfigError {
|
|||
let err_msg = match self {
|
||||
FormatConfigError::IOError(e) => e.to_string(),
|
||||
FormatConfigError::TomlError(e) => e.to_string(),
|
||||
FormatConfigError::Utf8Error(e) => e.to_string()
|
||||
FormatConfigError::Utf8Error(e) => e.to_string(),
|
||||
};
|
||||
|
||||
write!(f, "Format Config Error: {}", err_msg)
|
||||
|
@ -80,7 +80,6 @@ impl FormatConfig {
|
|||
contents.push_str(str::from_utf8(&format_file.data).unwrap());
|
||||
}
|
||||
|
||||
|
||||
Ok(toml::from_str(&contents)?)
|
||||
}
|
||||
}
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -1,18 +1,23 @@
|
|||
use crate::error::FormatyError;
|
||||
use crate::parser::parse_bytes_from_input_arg;
|
||||
use formatter::FormatConfig;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
use crate::error::FormatyError;
|
||||
|
||||
mod byte_stream;
|
||||
mod error;
|
||||
mod formatter;
|
||||
mod parser;
|
||||
mod error;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "Formaty", about = "Arbitrary Binary Data Formatting")]
|
||||
pub struct Args {
|
||||
#[structopt(short = "c", long="config", parse(from_os_str), help = "Path to the format config")]
|
||||
#[structopt(
|
||||
short = "c",
|
||||
long = "config",
|
||||
parse(from_os_str),
|
||||
help = "Path to the format config"
|
||||
)]
|
||||
config: Option<PathBuf>,
|
||||
|
||||
#[structopt(help = "Format to parse data as")]
|
||||
|
@ -27,7 +32,11 @@ fn formaty() -> Result<(), FormatyError> {
|
|||
|
||||
let config = FormatConfig::new(&args.config)?;
|
||||
|
||||
let format = config.formats.iter().find(|f| f.name == args.format).ok_or(FormatyError::FormatNotFound(args.format.to_string()))?;
|
||||
let format = config
|
||||
.formats
|
||||
.iter()
|
||||
.find(|f| f.name == args.format)
|
||||
.ok_or_else(|| FormatyError::FormatNotFound(args.format.to_string()))?;
|
||||
|
||||
let data = parse_bytes_from_input_arg(args.data).unwrap();
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::num::ParseIntError;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::num::ParseIntError;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ByteArrayParseErr {
|
||||
|
|
Loading…
Reference in New Issue