Skip to content

Commit

Permalink
Add missing fmt::Debug impls to public types in regex
Browse files Browse the repository at this point in the history
  • Loading branch information
lopopolo committed Dec 29, 2020
1 parent 334eb29 commit 77becd0
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/compile.rs
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::fmt;
use std::iter;
use std::result;
use std::sync::Arc;
Expand All @@ -25,6 +26,7 @@ struct Patch {

/// A compiler translates a regular expression AST to a sequence of
/// instructions. The sequence of instructions represents an NFA.
#[derive(Debug)]
pub struct Compiler {
insts: Vec<MaybeInst>,
compiled: Program,
Expand Down Expand Up @@ -1051,6 +1053,7 @@ impl<'a, 'b> CompileClass<'a, 'b> {
/// This uses similar idea to [`SparseSet`](../sparse/struct.SparseSet.html),
/// except it uses hashes as original indices and then compares full keys for
/// validation against `dense` array.
#[derive(Debug)]
struct SuffixCache {
sparse: Box<[usize]>,
dense: Vec<SuffixCacheEntry>,
Expand Down Expand Up @@ -1159,6 +1162,12 @@ impl ByteClassSet {
}
}

impl fmt::Debug for ByteClassSet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("ByteClassSet").field(&&self.0[..]).finish()
}
}

fn u32_to_usize(n: u32) -> usize {
// In case usize is less than 32 bits, we need to guard against overflow.
// On most platforms this compiles to nothing.
Expand Down
1 change: 1 addition & 0 deletions src/dfa.rs
Expand Up @@ -279,6 +279,7 @@ fn push_inst_ptr(data: &mut Vec<u8>, prev: &mut InstPtr, ip: InstPtr) {
*prev = ip;
}

#[derive(Debug)]
struct InstPtrs<'a> {
base: usize,
data: &'a [u8],
Expand Down
4 changes: 4 additions & 0 deletions src/exec.rs
Expand Up @@ -30,6 +30,7 @@ use utf8::next_utf8;
/// In particular, this manages the various compiled forms of a single regular
/// expression and the choice of which matching engine to use to execute a
/// regular expression.
#[derive(Debug)]
pub struct Exec {
/// All read only state.
ro: Arc<ExecReadOnly>,
Expand All @@ -49,6 +50,7 @@ pub struct ExecNoSync<'c> {
}

/// `ExecNoSyncStr` is like `ExecNoSync`, but matches on &str instead of &[u8].
#[derive(Debug)]
pub struct ExecNoSyncStr<'c>(ExecNoSync<'c>);

/// `ExecReadOnly` comprises all read only state for a regex. Namely, all such
Expand Down Expand Up @@ -97,6 +99,7 @@ struct ExecReadOnly {
/// Facilitates the construction of an executor by exposing various knobs
/// to control how a regex is executed and what kinds of resources it's
/// permitted to use.
#[derive(Debug)]
pub struct ExecBuilder {
options: RegexOptions,
match_type: Option<MatchType>,
Expand All @@ -106,6 +109,7 @@ pub struct ExecBuilder {

/// Parsed represents a set of parsed regular expressions and their detected
/// literals.
#[derive(Debug)]
struct Parsed {
exprs: Vec<Hir>,
prefixes: Literals,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -616,6 +616,7 @@ another matching engine with fixed memory requirements.
#![deny(missing_docs)]
#![cfg_attr(test, deny(warnings))]
#![cfg_attr(feature = "pattern", feature(pattern))]
#![warn(missing_debug_implementations)]

#[cfg(not(feature = "std"))]
compile_error!("`std` feature is currently required to build this crate");
Expand Down
1 change: 1 addition & 0 deletions src/literal/imp.rs
Expand Up @@ -232,6 +232,7 @@ impl Matcher {
}
}

#[derive(Debug)]
pub enum LiteralIter<'a> {
Empty,
Bytes(&'a [u8]),
Expand Down
2 changes: 2 additions & 0 deletions src/re_builder.rs
Expand Up @@ -47,6 +47,7 @@ macro_rules! define_builder {
/// A builder can be used to configure how the regex is built, for example, by
/// setting the default flags (which can be overridden in the expression
/// itself) or setting various limits.
#[derive(Debug)]
pub struct RegexBuilder(RegexOptions);

impl RegexBuilder {
Expand Down Expand Up @@ -244,6 +245,7 @@ macro_rules! define_set_builder {
/// A builder can be used to configure how the regexes are built, for example,
/// by setting the default flags (which can be overridden in the expression
/// itself) or setting various limits.
#[derive(Debug)]
pub struct RegexSetBuilder(RegexOptions);

impl RegexSetBuilder {
Expand Down
8 changes: 7 additions & 1 deletion src/re_bytes.rs
Expand Up @@ -690,6 +690,7 @@ impl Regex {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the matched byte string.
#[derive(Debug)]
pub struct Matches<'r, 't>(re_trait::Matches<'t, ExecNoSync<'r>>);

impl<'r, 't> Iterator for Matches<'r, 't> {
Expand All @@ -708,6 +709,7 @@ impl<'r, 't> Iterator for Matches<'r, 't> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the matched byte string.
#[derive(Debug)]
pub struct CaptureMatches<'r, 't>(
re_trait::CaptureMatches<'t, ExecNoSync<'r>>,
);
Expand All @@ -728,6 +730,7 @@ impl<'r, 't> Iterator for CaptureMatches<'r, 't> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the byte string being split.
#[derive(Debug)]
pub struct Split<'r, 't> {
finder: Matches<'r, 't>,
last: usize,
Expand Down Expand Up @@ -763,6 +766,7 @@ impl<'r, 't> Iterator for Split<'r, 't> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the byte string being split.
#[derive(Debug)]
pub struct SplitN<'r, 't> {
splits: Split<'r, 't>,
n: usize,
Expand Down Expand Up @@ -798,6 +802,7 @@ impl<'r, 't> Iterator for SplitN<'r, 't> {
/// whole matched region) is always unnamed.
///
/// `'r` is the lifetime of the compiled regular expression.
#[derive(Clone, Debug)]
pub struct CaptureNames<'r>(::std::slice::Iter<'r, Option<String>>);

impl<'r> Iterator for CaptureNames<'r> {
Expand Down Expand Up @@ -1057,7 +1062,7 @@ impl<'t, 'i> Index<&'i str> for Captures<'t> {
///
/// The lifetime `'c` corresponds to the lifetime of the `Captures` value, and
/// the lifetime `'t` corresponds to the originally matched text.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct SubCaptureMatches<'c, 't: 'c> {
caps: &'c Captures<'t>,
it: SubCapturesPosIter<'c>,
Expand Down Expand Up @@ -1173,6 +1178,7 @@ where
/// and performant (since capture groups don't need to be found).
///
/// `'t` is the lifetime of the literal text.
#[derive(Clone, Debug)]
pub struct NoExpand<'t>(pub &'t [u8]);

impl<'t> Replacer for NoExpand<'t> {
Expand Down
3 changes: 2 additions & 1 deletion src/re_set.rs
Expand Up @@ -320,6 +320,7 @@ impl<'a> IntoIterator for &'a SetMatches {
/// This will always produces matches in ascending order of index, where the
/// index corresponds to the index of the regex that matched with respect to
/// its position when initially building the set.
#[derive(Debug)]
pub struct SetMatchesIntoIter(iter::Enumerate<vec::IntoIter<bool>>);

impl Iterator for SetMatchesIntoIter {
Expand Down Expand Up @@ -359,7 +360,7 @@ impl DoubleEndedIterator for SetMatchesIntoIter {
/// This will always produces matches in ascending order of index, where the
/// index corresponds to the index of the regex that matched with respect to
/// its position when initially building the set.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct SetMatchesIter<'a>(iter::Enumerate<slice::Iter<'a, bool>>);

impl<'a> Iterator for SetMatchesIter<'a> {
Expand Down
29 changes: 28 additions & 1 deletion src/re_trait.rs
@@ -1,3 +1,5 @@
use std::fmt;

/// Slot is a single saved capture location. Note that there are two slots for
/// every capture in a regular expression (one slot each for the start and end
/// of the capture).
Expand Down Expand Up @@ -51,7 +53,7 @@ impl Locations {
/// Positions are byte indices in terms of the original string matched.
///
/// `'c` is the lifetime of the captures.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct SubCapturesPosIter<'c> {
idx: usize,
locs: &'c Locations,
Expand Down Expand Up @@ -172,6 +174,21 @@ where
}
}

impl<'t, R> fmt::Debug for Matches<'t, R>
where
R: RegularExpression + fmt::Debug,
R::Text: 't + fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Matches")
.field("re", &self.re)
.field("text", &self.text)
.field("last_end", &self.last_end)
.field("last_match", &self.last_match)
.finish()
}
}

impl<'t, R> Iterator for Matches<'t, R>
where
R: RegularExpression,
Expand Down Expand Up @@ -228,6 +245,16 @@ where
}
}

impl<'t, R> fmt::Debug for CaptureMatches<'t, R>
where
R: RegularExpression + fmt::Debug,
R::Text: 't + fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("CaptureMatches").field(&self.0).finish()
}
}

impl<'t, R> Iterator for CaptureMatches<'t, R>
where
R: RegularExpression,
Expand Down
8 changes: 7 additions & 1 deletion src/re_unicode.rs
Expand Up @@ -747,6 +747,7 @@ impl Regex {
/// whole matched region) is always unnamed.
///
/// `'r` is the lifetime of the compiled regular expression.
#[derive(Clone, Debug)]
pub struct CaptureNames<'r>(::std::slice::Iter<'r, Option<String>>);

impl<'r> Iterator for CaptureNames<'r> {
Expand All @@ -768,6 +769,7 @@ impl<'r> Iterator for CaptureNames<'r> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the string being split.
#[derive(Debug)]
pub struct Split<'r, 't> {
finder: Matches<'r, 't>,
last: usize,
Expand Down Expand Up @@ -803,6 +805,7 @@ impl<'r, 't> Iterator for Split<'r, 't> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the string being split.
#[derive(Debug)]
pub struct SplitN<'r, 't> {
splits: Split<'r, 't>,
n: usize,
Expand Down Expand Up @@ -1059,7 +1062,7 @@ impl<'t, 'i> Index<&'i str> for Captures<'t> {
///
/// The lifetime `'c` corresponds to the lifetime of the `Captures` value, and
/// the lifetime `'t` corresponds to the originally matched text.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct SubCaptureMatches<'c, 't: 'c> {
caps: &'c Captures<'t>,
it: SubCapturesPosIter<'c>,
Expand All @@ -1082,6 +1085,7 @@ impl<'c, 't> Iterator for SubCaptureMatches<'c, 't> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the matched string.
#[derive(Debug)]
pub struct CaptureMatches<'r, 't>(
re_trait::CaptureMatches<'t, ExecNoSyncStr<'r>>,
);
Expand All @@ -1105,6 +1109,7 @@ impl<'r, 't> Iterator for CaptureMatches<'r, 't> {
///
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
/// lifetime of the matched string.
#[derive(Debug)]
pub struct Matches<'r, 't>(re_trait::Matches<'t, ExecNoSyncStr<'r>>);

impl<'r, 't> Iterator for Matches<'r, 't> {
Expand Down Expand Up @@ -1215,6 +1220,7 @@ where
/// and performant (since capture groups don't need to be found).
///
/// `'t` is the lifetime of the literal text.
#[derive(Clone, Debug)]
pub struct NoExpand<'t>(pub &'t str);

impl<'t> Replacer for NoExpand<'t> {
Expand Down

0 comments on commit 77becd0

Please sign in to comment.