aboutsummaryrefslogtreecommitdiff
path: root/src/validate_ipv4_address.rs
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2020-10-30 13:42:07 -0700
committerRichard Walters <rwalters@digitalstirling.com>2020-10-30 13:42:07 -0700
commit9d961981db81d10a7315160fbcb45b1ebaf4c119 (patch)
tree8f34548cf5152a49ab90e0eb2ffee47392793f42 /src/validate_ipv4_address.rs
parent99a6971893b7d08c1d976e4eb99701e36d80afb8 (diff)
Add and apply rustfmt configuration
Diffstat (limited to 'src/validate_ipv4_address.rs')
-rw-r--r--src/validate_ipv4_address.rs43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/validate_ipv4_address.rs b/src/validate_ipv4_address.rs
index 98254df..3c524ce 100644
--- a/src/validate_ipv4_address.rs
+++ b/src/validate_ipv4_address.rs
@@ -1,10 +1,10 @@
#![warn(clippy::pedantic)]
-use super::character_classes::{
- DIGIT,
+use super::{
+ character_classes::DIGIT,
+ context::Context,
+ error::Error,
};
-use super::context::Context;
-use super::error::Error;
struct Shared {
num_groups: usize,
@@ -20,7 +20,9 @@ impl State {
fn finalize(self) -> Result<(), Error> {
match self {
Self::NotInOctet(_) => Err(Error::TruncatedHost),
- Self::ExpectDigitOrDot(state) => Self::finalize_expect_digit_or_dot(state),
+ Self::ExpectDigitOrDot(state) => {
+ Self::finalize_expect_digit_or_dot(state)
+ },
}
}
@@ -40,20 +42,28 @@ impl State {
}
fn new() -> Self {
- Self::NotInOctet(Shared{
+ Self::NotInOctet(Shared {
num_groups: 0,
octet_buffer: String::new(),
})
}
- fn next(self, c: char) -> Result<Self, Error> {
+ fn next(
+ self,
+ c: char,
+ ) -> Result<Self, Error> {
match self {
Self::NotInOctet(state) => Self::next_not_in_octet(state, c),
- Self::ExpectDigitOrDot(state) => Self::next_expect_digit_or_dot(state, c),
+ Self::ExpectDigitOrDot(state) => {
+ Self::next_expect_digit_or_dot(state, c)
+ },
}
}
- fn next_not_in_octet(state: Shared, c: char) -> Result<Self, Error> {
+ fn next_not_in_octet(
+ state: Shared,
+ c: char,
+ ) -> Result<Self, Error> {
let mut state = state;
if DIGIT.contains(&c) {
state.octet_buffer.push(c);
@@ -63,7 +73,10 @@ impl State {
}
}
- fn next_expect_digit_or_dot(state: Shared, c: char)-> Result<Self, Error> {
+ fn next_expect_digit_or_dot(
+ state: Shared,
+ c: char,
+ ) -> Result<Self, Error> {
let mut state = state;
if c == '.' {
state.num_groups += 1;
@@ -85,13 +98,13 @@ impl State {
}
pub fn validate_ipv4_address<T>(address: T) -> Result<(), Error>
- where T: AsRef<str>
+where
+ T: AsRef<str>,
{
- address.as_ref()
+ address
+ .as_ref()
.chars()
- .try_fold(State::new(), |machine, c| {
- machine.next(c)
- })?
+ .try_fold(State::new(), |machine, c| machine.next(c))?
.finalize()
}