Skip to content

Commit

Permalink
REMOVE ME: Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharding committed Feb 21, 2024
1 parent 43752cf commit b0a9120
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
7 changes: 2 additions & 5 deletions examples/hexy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
use std::fmt;
use std::str::FromStr;

use hex_conservative::{
fmt_hex_exact, Case, DisplayHex, FromHex, HexToArrayError,
};
use hex_conservative::{fmt_hex_exact, Case, DisplayHex, FromHex, HexToArrayError};

fn main() {
let s = "deadbeefcafebabedeadbeefcafebabedeadbeefcafebabedeadbeefcafebabe";
Expand Down Expand Up @@ -74,8 +72,7 @@ impl fmt::UpperHex for Hexy {
impl FromHex for Hexy {
type Error = HexToArrayError;

fn from_hex(s: &str) -> Result<Self, Self::Error>
{
fn from_hex(s: &str) -> Result<Self, Self::Error> {
// Errors if the input is invalid
let a = <[u8; 32] as FromHex>::from_hex(s)?;
Ok(Hexy { data: a })
Expand Down
4 changes: 1 addition & 3 deletions examples/wrap_array_display_hex_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ pub struct Wrap([u8; 32]);
impl FromHex for Wrap {
type Error = HexToArrayError;

fn from_hex(s: &str) -> Result<Self, Self::Error> {
Ok(Self(FromHex::from_hex(s)?))
}
fn from_hex(s: &str) -> Result<Self, Self::Error> { Ok(Self(FromHex::from_hex(s)?)) }
}

/// Use `DisplayArray` to display the `Wrap` type.
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/hex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hex::{FromHex, DisplayHex};
use hex::{DisplayHex, FromHex};
use honggfuzz::fuzz;

const LEN: usize = 32; // Arbitrary amount of data.
Expand Down
6 changes: 2 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ impl fmt::Display for HexToArrayError {
use HexToArrayError::*;

match *self {
InvalidChar(ref e) =>
crate::write_err!(f, "failed to parse hex digit"; e),
InvalidLength(ref e) =>
write_err!(f, "failed to parse hex"; e),
InvalidChar(ref e) => crate::write_err!(f, "failed to parse hex digit"; e),
InvalidLength(ref e) => write_err!(f, "failed to parse hex"; e),
}
}
}
Expand Down
30 changes: 12 additions & 18 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::error::InvalidCharError;
pub use crate::error::{HexToBytesError, OddLengthStringError};

/// Iterator yielding bytes decoded from an iterator of pairs of hex digits.
pub struct HexToBytesIter<T: Iterator<Item=[u8; 2]>> {
pub struct HexToBytesIter<T: Iterator<Item = [u8; 2]>> {
iter: T,
}

Expand All @@ -41,15 +41,13 @@ impl<'a> HexToBytesIter<HexDigitsIter<'a>> {
}
}

impl<T: Iterator<Item=[u8; 2]>> HexToBytesIter<T> {
impl<T: Iterator<Item = [u8; 2]>> HexToBytesIter<T> {
/// Constructs a custom hex decoding iterator from another iterator.
#[inline]
pub fn from_pairs(iter: T) -> Self {
Self { iter }
}
pub fn from_pairs(iter: T) -> Self { Self { iter } }
}

impl<T: Iterator<Item=[u8; 2]>> Iterator for HexToBytesIter<T> {
impl<T: Iterator<Item = [u8; 2]>> Iterator for HexToBytesIter<T> {
type Item = Result<u8, InvalidCharError>;

#[inline]
Expand All @@ -71,7 +69,7 @@ impl<T: Iterator<Item=[u8; 2]>> Iterator for HexToBytesIter<T> {
}
}

impl<T: Iterator<Item=[u8; 2]> + DoubleEndedIterator> DoubleEndedIterator for HexToBytesIter<T> {
impl<T: Iterator<Item = [u8; 2]> + DoubleEndedIterator> DoubleEndedIterator for HexToBytesIter<T> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
let [hi, lo] = self.iter.next_back()?;
Expand All @@ -85,12 +83,12 @@ impl<T: Iterator<Item=[u8; 2]> + DoubleEndedIterator> DoubleEndedIterator for He
}
}

impl<T: Iterator<Item=[u8; 2]> + ExactSizeIterator> ExactSizeIterator for HexToBytesIter<T> { }
impl<T: Iterator<Item = [u8; 2]> + ExactSizeIterator> ExactSizeIterator for HexToBytesIter<T> {}

impl<T: Iterator<Item=[u8; 2]> + FusedIterator> FusedIterator for HexToBytesIter<T> {}
impl<T: Iterator<Item = [u8; 2]> + FusedIterator> FusedIterator for HexToBytesIter<T> {}

#[cfg(any(feature = "std", feature = "core2"))]
impl<T: Iterator<Item=[u8; 2]> + FusedIterator> io::Read for HexToBytesIter<T> {
impl<T: Iterator<Item = [u8; 2]> + FusedIterator> io::Read for HexToBytesIter<T> {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut bytes_read = 0usize;
Expand Down Expand Up @@ -120,9 +118,7 @@ pub struct HexDigitsIter<'a> {

impl<'a> HexDigitsIter<'a> {
#[inline]
fn new_unchecked(digits: &'a [u8]) -> Self {
Self { iter: digits.chunks_exact(2) }
}
fn new_unchecked(digits: &'a [u8]) -> Self { Self { iter: digits.chunks_exact(2) } }
}

impl<'a> Iterator for HexDigitsIter<'a> {
Expand All @@ -134,9 +130,7 @@ impl<'a> Iterator for HexDigitsIter<'a> {
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }

#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> {
Expand All @@ -156,9 +150,9 @@ impl<'a> DoubleEndedIterator for HexDigitsIter<'a> {
}
}

impl<'a> ExactSizeIterator for HexDigitsIter<'a> { }
impl<'a> ExactSizeIterator for HexDigitsIter<'a> {}

impl<'a> core::iter::FusedIterator for HexDigitsIter<'a> { }
impl<'a> core::iter::FusedIterator for HexDigitsIter<'a> {}

/// `hi` and `lo` are bytes representing hex characters.
fn hex_chars_to_byte(hi: u8, lo: u8) -> Result<u8, InvalidCharError> {
Expand Down

0 comments on commit b0a9120

Please sign in to comment.