Fmt + Clippy

pull/1/head
Joey Hines 2022-04-09 12:40:37 -06:00
parent 59351fb699
commit 6407335362
No known key found for this signature in database
GPG Key ID: 80F567B5C968F91B
4 changed files with 28 additions and 21 deletions

View File

@ -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::format::FormatError;
use crate::formatter::FormatConfigError; use crate::formatter::FormatConfigError;
use crate::parser::ByteArrayParseErr;
use std::error::Error;
use std::fmt::{Display, Formatter};
#[derive(Debug)] #[derive(Debug)]
pub enum FormatyError { pub enum FormatyError {
ByteArrayParseError(ByteArrayParseErr), ByteArrayParseError(ByteArrayParseErr),
FormatError(FormatError), FormatError(FormatError),
FormatConfigError(FormatConfigError), FormatConfigError(FormatConfigError),
FormatNotFound(String) FormatNotFound(String),
} }
impl From<ByteArrayParseErr> for FormatyError { impl From<ByteArrayParseErr> for FormatyError {
@ -37,11 +36,11 @@ impl Display for FormatyError {
FormatyError::ByteArrayParseError(e) => e.to_string(), FormatyError::ByteArrayParseError(e) => e.to_string(),
FormatyError::FormatError(e) => e.to_string(), FormatyError::FormatError(e) => e.to_string(),
FormatyError::FormatConfigError(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) write!(f, "{}", err_msg)
} }
} }
impl Error for FormatyError {} impl Error for FormatyError {}

View File

@ -2,21 +2,21 @@ pub mod format;
mod printers; mod printers;
use crate::formatter::format::Format; use crate::formatter::format::Format;
use rust_embed::RustEmbed;
use serde::Deserialize; use serde::Deserialize;
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::PathBuf; use std::path::PathBuf;
use rust_embed::RustEmbed;
use std::str; use std::str;
use std::str::Utf8Error;
use std::fmt::{Display, Formatter};
use std::error::Error;
#[derive(Debug)] #[derive(Debug)]
#[allow(clippy::enum_variant_names)]
pub enum FormatConfigError { pub enum FormatConfigError {
IOError(std::io::Error), IOError(std::io::Error),
TomlError(toml::de::Error), TomlError(toml::de::Error),
Utf8Error(Utf8Error) Utf8Error(std::str::Utf8Error),
} }
impl Error for FormatConfigError {} impl Error for FormatConfigError {}
@ -33,8 +33,8 @@ impl From<toml::de::Error> for FormatConfigError {
} }
} }
impl From<Utf8Error> for FormatConfigError { impl From<std::str::Utf8Error> for FormatConfigError {
fn from(e: Utf8Error) -> Self { fn from(e: std::str::Utf8Error) -> Self {
Self::Utf8Error(e) Self::Utf8Error(e)
} }
} }
@ -44,7 +44,7 @@ impl Display for FormatConfigError {
let err_msg = match self { let err_msg = match self {
FormatConfigError::IOError(e) => e.to_string(), FormatConfigError::IOError(e) => e.to_string(),
FormatConfigError::TomlError(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) write!(f, "Format Config Error: {}", err_msg)
@ -80,7 +80,6 @@ impl FormatConfig {
contents.push_str(str::from_utf8(&format_file.data).unwrap()); contents.push_str(str::from_utf8(&format_file.data).unwrap());
} }
Ok(toml::from_str(&contents)?) Ok(toml::from_str(&contents)?)
} }
} }

View File

@ -1,18 +1,23 @@
use crate::error::FormatyError;
use crate::parser::parse_bytes_from_input_arg; use crate::parser::parse_bytes_from_input_arg;
use formatter::FormatConfig; use formatter::FormatConfig;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt; use structopt::StructOpt;
use crate::error::FormatyError;
mod byte_stream; mod byte_stream;
mod error;
mod formatter; mod formatter;
mod parser; mod parser;
mod error;
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt(name = "Formaty", about = "Arbitrary Binary Data Formatting")] #[structopt(name = "Formaty", about = "Arbitrary Binary Data Formatting")]
pub struct Args { 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>, config: Option<PathBuf>,
#[structopt(help = "Format to parse data as")] #[structopt(help = "Format to parse data as")]
@ -27,7 +32,11 @@ fn formaty() -> Result<(), FormatyError> {
let config = FormatConfig::new(&args.config)?; 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(); let data = parse_bytes_from_input_arg(args.data).unwrap();

View File

@ -1,5 +1,5 @@
use std::num::ParseIntError;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::num::ParseIntError;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ByteArrayParseErr { pub enum ByteArrayParseErr {