From c63bf04601bdd7ccfd0dc5de0cf36c78275b5197 Mon Sep 17 00:00:00 2001 From: Damian Poddebniak Date: Tue, 20 Jul 2021 21:51:44 +0200 Subject: [PATCH] Reformat code --- examples/parse_command.rs | 3 +- src/parse/address.rs | 3 +- src/parse/command.rs | 9 +++--- src/parse/imf.rs | 62 ++++++++++++++++++++++----------------- src/parse/mod.rs | 6 ++-- src/parse/response.rs | 9 +++--- src/parse/trace.rs | 21 ++++++------- src/types.rs | 6 ++-- 8 files changed, 68 insertions(+), 51 deletions(-) diff --git a/examples/parse_command.rs b/examples/parse_command.rs index 0bf1fd7..91e7e77 100644 --- a/examples/parse_command.rs +++ b/examples/parse_command.rs @@ -1,6 +1,7 @@ -use smtp_codec::parse::command::command; use std::io::Write; +use smtp_codec::parse::command::command; + fn main() -> std::io::Result<()> { let mut args = std::env::args(); diff --git a/src/parse/address.rs b/src/parse/address.rs index 0a7a4da..a548612 100644 --- a/src/parse/address.rs +++ b/src/parse/address.rs @@ -1,6 +1,5 @@ //! 4.1.3. Address Literals (RFC 5321) -use crate::parse::Ldh_str; use abnf_core::streaming::is_DIGIT; use nom::{ branch::alt, @@ -12,6 +11,8 @@ use nom::{ IResult, }; +use crate::parse::Ldh_str; + /// address-literal = "[" ( /// IPv4-address-literal / /// IPv6-address-literal / diff --git a/src/parse/command.rs b/src/parse/command.rs index 3b64600..f38ad8f 100644 --- a/src/parse/command.rs +++ b/src/parse/command.rs @@ -1,7 +1,3 @@ -use crate::{ - parse::{address::address_literal, base64, Atom, Domain, Quoted_string, String}, - types::{Command, DomainOrAddress, Parameter}, -}; use abnf_core::streaming::{is_ALPHA, is_DIGIT, CRLF, SP}; use nom::{ branch::alt, @@ -12,6 +8,11 @@ use nom::{ IResult, }; +use crate::{ + parse::{address::address_literal, base64, Atom, Domain, Quoted_string, String}, + types::{Command, DomainOrAddress, Parameter}, +}; + pub fn command(input: &[u8]) -> IResult<&[u8], Command> { alt(( helo, ehlo, mail, rcpt, data, rset, vrfy, expn, help, noop, quit, diff --git a/src/parse/imf.rs b/src/parse/imf.rs index 7c810e6..9025677 100644 --- a/src/parse/imf.rs +++ b/src/parse/imf.rs @@ -4,7 +4,6 @@ /// 3.2.1. Quoted characters pub mod quoted_characters { - use super::obsolete::obs_qp; use abnf_core::streaming::{is_VCHAR, WSP}; use nom::{ branch::alt, @@ -14,6 +13,8 @@ pub mod quoted_characters { IResult, }; + use super::obsolete::obs_qp; + /// quoted-pair = ("\" (VCHAR / WSP)) / obs-qp pub fn quoted_pair(input: &[u8]) -> IResult<&[u8], &[u8]> { let parser = alt(( @@ -57,7 +58,6 @@ pub mod folding_ws_and_comment { /// 3.2.3. Atom pub mod atom { - use super::folding_ws_and_comment::CFWS; use abnf_core::streaming::{is_ALPHA, is_DIGIT}; use nom::{ bytes::streaming::{tag, take_while1}, @@ -67,6 +67,8 @@ pub mod atom { IResult, }; + use super::folding_ws_and_comment::CFWS; + /// Printable US-ASCII characters not including specials. /// Used for atoms. /// @@ -131,11 +133,6 @@ pub mod atom { /// 3.2.4. Quoted Strings pub mod quoted_strings { - use super::{ - folding_ws_and_comment::{CFWS, FWS}, - obsolete::is_obs_qtext, - quoted_characters::quoted_pair, - }; use abnf_core::streaming::DQUOTE; use nom::{ branch::alt, @@ -146,6 +143,12 @@ pub mod quoted_strings { IResult, }; + use super::{ + folding_ws_and_comment::{CFWS, FWS}, + obsolete::is_obs_qtext, + quoted_characters::quoted_pair, + }; + /// Printable US-ASCII characters not including "\" or the quote character. /// /// qtext = %d33 / %d35-91 / %d93-126 / obs-qtext @@ -185,9 +188,10 @@ pub mod quoted_strings { /// 3.2.5. Miscellaneous Tokens pub mod miscellaneous { - use super::{atom::atom, quoted_strings::quoted_string}; use nom::{branch::alt, IResult}; + use super::{atom::atom, quoted_strings::quoted_string}; + /// word = atom / quoted-string pub fn word(input: &[u8]) -> IResult<&[u8], &[u8]> { alt((atom, quoted_string))(input) @@ -202,7 +206,6 @@ pub mod miscellaneous { /// 3.3. Date and Time Specification pub mod datetime { - use super::folding_ws_and_comment::{CFWS, FWS}; use abnf_core::streaming::is_DIGIT; use nom::{ branch::alt, @@ -212,6 +215,8 @@ pub mod datetime { IResult, }; + use super::folding_ws_and_comment::{CFWS, FWS}; + // date-time = [ day-of-week "," ] date time [CFWS] pub fn date_time(input: &[u8]) -> IResult<&[u8], &[u8]> { let parser = tuple((opt(tuple((day_of_week, tag(b",")))), date, time, opt(CFWS))); @@ -365,12 +370,6 @@ pub mod datetime { /// 3.4.1. Addr-Spec Specification pub mod addr_spec { - use super::{ - atom::dot_atom, - folding_ws_and_comment::{CFWS, FWS}, - obsolete::{obs_domain, obs_dtext, obs_local_part}, - quoted_strings::quoted_string, - }; use nom::{ branch::alt, bytes::streaming::{tag, take_while_m_n}, @@ -380,6 +379,13 @@ pub mod addr_spec { IResult, }; + use super::{ + atom::dot_atom, + folding_ws_and_comment::{CFWS, FWS}, + obsolete::{obs_domain, obs_dtext, obs_local_part}, + quoted_strings::quoted_string, + }; + // addr-spec = local-part "@" domain /// local-part = dot-atom / quoted-string / obs-local-part @@ -442,12 +448,6 @@ pub mod addr_spec { /// 3.6.4. Identification Fields pub mod identification { - use super::{ - addr_spec::dtext, - atom::dot_atom_text, - folding_ws_and_comment::CFWS, - obsolete::{obs_id_left, obs_id_right}, - }; use nom::{ branch::alt, bytes::streaming::tag, @@ -457,6 +457,13 @@ pub mod identification { IResult, }; + use super::{ + addr_spec::dtext, + atom::dot_atom_text, + folding_ws_and_comment::CFWS, + obsolete::{obs_id_left, obs_id_right}, + }; + // message-id = "Message-ID:" msg-id CRLF // ... @@ -513,12 +520,6 @@ pub mod identification { /// 4.1. Miscellaneous Obsolete Tokens pub mod obsolete { - use super::{ - addr_spec::{domain, local_part}, - atom::atom, - miscellaneous::word, - quoted_characters::quoted_pair, - }; use abnf_core::streaming::{CR, LF}; use nom::{ branch::alt, @@ -529,6 +530,13 @@ pub mod obsolete { IResult, }; + use super::{ + addr_spec::{domain, local_part}, + atom::atom, + miscellaneous::word, + quoted_characters::quoted_pair, + }; + /// US-ASCII control characters that do not include the carriage /// return, line feed, and white space characters /// diff --git a/src/parse/mod.rs b/src/parse/mod.rs index d58fa6c..81f04c6 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -1,6 +1,7 @@ #![allow(non_snake_case)] -use crate::{parse::imf::atom::is_atext, types::AtomOrQuoted, utils::unescape_quoted}; +use std::{borrow::Cow, str::from_utf8}; + use abnf_core::streaming::{is_ALPHA, is_DIGIT, DQUOTE}; use nom::{ branch::alt, @@ -11,7 +12,8 @@ use nom::{ sequence::{delimited, tuple}, IResult, }; -use std::{borrow::Cow, str::from_utf8}; + +use crate::{parse::imf::atom::is_atext, types::AtomOrQuoted, utils::unescape_quoted}; pub mod address; pub mod command; diff --git a/src/parse/response.rs b/src/parse/response.rs index bbf4570..115dc87 100644 --- a/src/parse/response.rs +++ b/src/parse/response.rs @@ -1,7 +1,3 @@ -use crate::{ - parse::{address::address_literal, number, Domain}, - types::{AuthMechanism, Capability, Response}, -}; use abnf_core::streaming::{is_ALPHA, is_DIGIT, CRLF, SP}; use nom::{ branch::alt, @@ -12,6 +8,11 @@ use nom::{ IResult, }; +use crate::{ + parse::{address::address_literal, number, Domain}, + types::{AuthMechanism, Capability, Response}, +}; + /// Greeting = ( "220 " (Domain / address-literal) [ SP textstring ] CRLF ) / /// ( "220-" (Domain / address-literal) [ SP textstring ] CRLF /// *( "220-" [ textstring ] CRLF ) diff --git a/src/parse/trace.rs b/src/parse/trace.rs index 9a45241..76e18fa 100644 --- a/src/parse/trace.rs +++ b/src/parse/trace.rs @@ -1,13 +1,3 @@ -use crate::parse::{ - address::address_literal, - command::{Mailbox, Path, Reverse_path}, - imf::{ - datetime::date_time, - folding_ws_and_comment::{CFWS, FWS}, - identification::msg_id, - }, - Atom, Domain, String, -}; /// 4.4. Trace Information (RFC 5321) use abnf_core::streaming::CRLF; use nom::{ @@ -19,6 +9,17 @@ use nom::{ IResult, }; +use crate::parse::{ + address::address_literal, + command::{Mailbox, Path, Reverse_path}, + imf::{ + datetime::date_time, + folding_ws_and_comment::{CFWS, FWS}, + identification::msg_id, + }, + Atom, Domain, String, +}; + /// Return-path-line = "Return-Path:" FWS Reverse-path pub fn Return_path_line(input: &[u8]) -> IResult<&[u8], &[u8]> { let parser = tuple((tag_no_case(b"Return-Path:"), FWS, Reverse_path, CRLF)); diff --git a/src/types.rs b/src/types.rs index 02ba0b4..0fea12c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,7 +1,9 @@ -use crate::utils::escape_quoted; +use std::io::Write; + #[cfg(feature = "serdex")] use serde::{Deserialize, Serialize}; -use std::io::Write; + +use crate::utils::escape_quoted; #[derive(Clone, Debug, PartialEq, Eq)] pub enum Command {