Skip to content

Commit

Permalink
Remove unused FormatUnit newtype.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomprince committed Jan 15, 2017
1 parent 5a76b50 commit 37b6cb0
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/format.rs
Expand Up @@ -8,9 +8,9 @@ use std::fmt::Formatter;
use self::FormatText::{Method, URI, Status, ResponseTime, RemoteAddr, RequestTime};

/// A formatting style for the `Logger`, consisting of multiple
/// `FormatUnit`s concatenated into one line.
/// `FormatText`s concatenated into one line.
#[derive(Clone)]
pub struct Format(Vec<FormatUnit>);
pub struct Format(Vec<FormatText>);

impl Default for Format {
/// Return the default formatting style for the `Logger`:
Expand Down Expand Up @@ -94,13 +94,13 @@ impl<'a> FormatParser<'a> {

// Some(None) means there was a parse error and this FormatParser should be abandoned.
impl<'a> Iterator for FormatParser<'a> {
type Item = Option<FormatUnit>;
type Item = Option<FormatText>;

fn next(&mut self) -> Option<Option<FormatUnit>> {
fn next(&mut self) -> Option<Option<FormatText>> {
// If the parser has been cancelled or errored for some reason.
if self.finished { return None }

// Try to parse a new FormatUnit.
// Try to parse a new FormatText.
match self.chars.next() {
// Parse a recognized object.
//
Expand Down Expand Up @@ -139,8 +139,8 @@ impl<'a> Iterator for FormatParser<'a> {
}
};

Some(Some(FormatUnit {text: text}))
},
Some(Some(text))
}

// Parse a regular string part of the format string.
Some(c) => {
Expand All @@ -150,9 +150,7 @@ impl<'a> Iterator for FormatParser<'a> {
loop {
match self.chars.peek() {
// Done parsing.
Some(&'{') | None => {
return Some(Some(FormatUnit {text: FormatText::Str(buffer)}))
},
Some(&'{') | None => return Some(Some(FormatText::Str(buffer))),

Some(_) => {
buffer.push(self.chars.next().unwrap())
Expand Down Expand Up @@ -181,13 +179,6 @@ pub enum FormatText {
RequestTime
}

/// A `FormatText` with associated style information.
#[derive(Clone)]
#[doc(hidden)]
pub struct FormatUnit {
pub text: FormatText,
}


pub struct FormatDisplay<'a> {
format: &'a Format,
Expand All @@ -199,7 +190,7 @@ impl<'a> fmt::Display for FormatDisplay<'a> {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
let Format(ref format) = *self.format;
for unit in format {
(self.render)(fmt, &unit.text)?;
(self.render)(fmt, unit)?;
}
Ok(())
}
Expand Down

0 comments on commit 37b6cb0

Please sign in to comment.