From 6407335362dde8c401c68b92eadd6f16e2b173f9 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 9 Apr 2022 12:40:37 -0600 Subject: [PATCH] Fmt + Clippy --- src/error/mod.rs | 13 ++++++------- src/formatter/mod.rs | 17 ++++++++--------- src/main.rs | 17 +++++++++++++---- src/parser/mod.rs | 2 +- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/error/mod.rs b/src/error/mod.rs index 88fac4c..d22c3a5 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -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 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 {} \ No newline at end of file +impl Error for FormatyError {} diff --git a/src/formatter/mod.rs b/src/formatter/mod.rs index c87eb10..a24c9a3 100644 --- a/src/formatter/mod.rs +++ b/src/formatter/mod.rs @@ -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 for FormatConfigError { } } -impl From for FormatConfigError { - fn from(e: Utf8Error) -> Self { +impl From 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)?) } } diff --git a/src/main.rs b/src/main.rs index 146abcc..1e2865c 100644 --- a/src/main.rs +++ b/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, #[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(); diff --git a/src/parser/mod.rs b/src/parser/mod.rs index ba612c5..d2b5e21 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,5 +1,5 @@ -use std::num::ParseIntError; use std::fmt::{Display, Formatter}; +use std::num::ParseIntError; #[derive(Debug, Clone)] pub enum ByteArrayParseErr {