regex_chunker/
ctrl.rs

1/*!
2A bunch of enums that control the behavior of chunkers.
3*/
4#[derive(Clone, Copy, Debug, PartialEq)]
5pub(crate) enum ErrorStatus {
6    Ok,
7    Errored,
8    Continue,
9    Ignore,
10}
11impl Eq for ErrorStatus {}
12
13/// Type for specifying a Chunker's behavior upon encountering an error.
14#[derive(Clone, Copy, Debug)]
15pub enum ErrorResponse {
16    /// Return `Some(Err(error))` once then None thereafter. This is
17    /// the default behavior.
18    Halt,
19    /// Return `Some(Err(error))` but attempt to recover and continue.
20    /// This may result in an endless stream of errors.
21    Continue,
22    /// Attempt to recover and continue until it's possible to return
23    /// another `Some(Ok())`. This may result in a deadlock.
24    Ignore,
25}
26
27/// Specify what the chunker should do with the matched text.
28#[derive(Clone, Copy, Debug, Default)]
29pub enum MatchDisposition {
30    /// Discard the matched text; only return the text
31    /// _between_ matches. This is the default behavior.
32    #[default]
33    Drop,
34    /// Treat the matched text like the end of the preceding chunk.
35    Append,
36    /// Treat the matched text like the beginning of the
37    /// following chunk.
38    Prepend,
39}
40
41/// Type for specifying a [`StringAdapter`](crate::StringAdapter)'s
42/// behavior upon encountering non-UTF-8 data.
43#[derive(Clone, Copy, Debug, Default)]
44pub enum Utf8FailureMode {
45    /// Lossily convert to UTF-8 (with
46    /// [`String::from_utf8_lossy`](std::string::String::from_utf8_lossy)).
47    Lossy,
48    /// Report an error and stop reading (return `Some(Err(RcErr))` once
49    /// and then `None` thereafter.
50    #[default]
51    Fatal,
52    /// Report an error but attempt to continue (keep returning
53    /// `Some(Err(RcErr))` until the it starts reading UTF-8 from the
54    /// `source` again.
55    Continue,
56}