Skip to content

Commit

Permalink
better accommodate the std feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bobozaur committed Feb 5, 2025
1 parent bb5795d commit c350c9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/ahocorasick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::{
use alloc::{string::String, sync::Arc, vec::Vec};

use crate::{
automaton::{self, Automaton, OverlappingState, ReplacingReader},
automaton::{self, Automaton, OverlappingState},
dfa,
nfa::{contiguous, noncontiguous},
util::{
Expand Down Expand Up @@ -1904,7 +1904,7 @@ impl AhoCorasick {
rdr: R,
replace_with: &'a [B],
) -> std::io::Result<
ReplacingReader<
automaton::ReplacingReader<
'_,
impl Automaton,
R,
Expand Down Expand Up @@ -1992,7 +1992,7 @@ impl AhoCorasick {
&self,
rdr: R,
replace_with: F,
) -> std::io::Result<ReplacingReader<'_, impl Automaton, R, F>>
) -> std::io::Result<automaton::ReplacingReader<'_, impl Automaton, R, F>>
where
R: std::io::Read,
F: FnMut(&Match, &[u8]) -> std::io::Result<B>,
Expand Down
15 changes: 8 additions & 7 deletions src/automaton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Aho-Corasick automaton. It also provides access to lower level APIs that
permit walking the state transitions of an Aho-Corasick automaton manually.
*/

use core::ops::Range;

use alloc::{string::String, vec::Vec};

use crate::util::{
Expand Down Expand Up @@ -1333,9 +1331,9 @@ enum StreamChunk<'r> {
#[derive(Debug)]
enum StreamChunkRange {
/// A chunk range that does not contain any matches.
NonMatch { range: Range<usize> },
NonMatch { range: core::ops::Range<usize> },
/// A chunk range that precisely contains a match.
Match { range: Range<usize>, mat: Match },
Match { range: core::ops::Range<usize>, mat: Match },
}

/// A wrapper reader that replaces matches found in the provided reader as
Expand All @@ -1356,6 +1354,7 @@ pub struct ReplacingReader<'a, A, R, F> {
state: ReaderState,
}

#[cfg(feature = "std")]
impl<'a, A, R, F, B> ReplacingReader<'a, A, R, F>
where
A: Automaton,
Expand Down Expand Up @@ -1395,6 +1394,7 @@ where
}
}

#[cfg(feature = "std")]
impl<'a, A, R, F, B> std::io::Read for ReplacingReader<'a, A, R, F>
where
A: Automaton,
Expand Down Expand Up @@ -1429,7 +1429,7 @@ where
range.start += amt;

// Fetch a new chunk if we finished reading this one.
if Range::is_empty(range) {
if core::ops::Range::is_empty(range) {
self.state = ReaderState::Read;
}
}
Expand Down Expand Up @@ -1462,11 +1462,12 @@ where
}
}

#[cfg(feature = "std")]
#[derive(Debug)]
enum ReaderState {
Read,
Consume { range: Range<usize> },
Replace { range: Range<usize>, mat: Match, offset: usize },
Consume { range: core::ops::Range<usize> },
Replace { range: core::ops::Range<usize>, mat: Match, offset: usize },
End,
}

Expand Down

0 comments on commit c350c9f

Please sign in to comment.