Skip to content

Commit

Permalink
scannerless: fix Debug formatting for Pat.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jul 23, 2019
1 parent 603178e commit 9ff39b8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/scannerless.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
use crate::rule::{MatchesEmpty, MaybeKnown};
use std::char;
use std::fmt;
use std::ops::{self, Bound, RangeBounds};

pub type Context<S = String> = crate::context::Context<Pat<S>>;

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Pat<S = String, C = char> {
String(S),
Range(C, C),
}

impl<S: fmt::Debug> fmt::Debug for Pat<S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Pat::String(s) => s.fmt(f),
&Pat::Range(start, end) => {
if start != '\0' {
start.fmt(f)?;
}
f.write_str("..")?;
if end != char::MAX {
f.write_str("=")?;
end.fmt(f)?;
}
Ok(())
}
}
}
}

impl<'a, C> From<&'a str> for Pat<&'a str, C> {
fn from(s: &'a str) -> Self {
Pat::String(s)
Expand Down

0 comments on commit 9ff39b8

Please sign in to comment.