1 use core
::mem
::size_of
;
3 use crate::util
::wire
::{self, DeserializeError, Endian, SerializeError}
;
5 /// The kind of anchored starting configurations to support in a DFA.
7 /// Fully compiled DFAs need to be explicitly configured as to which anchored
8 /// starting configurations to support. The reason for not just supporting
9 /// everything unconditionally is that it can use more resources (such as
10 /// memory and build time). The downside of this is that if you try to execute
11 /// a search using an [`Anchored`](crate::Anchored) mode that is not supported
12 /// by the DFA, then the search will return an error.
13 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
15 /// Support both anchored and unanchored searches.
17 /// Support only unanchored searches. Requesting an anchored search will
20 /// Note that even if an unanchored search is requested, the pattern itself
21 /// may still be anchored. For example, `^abc` will only match `abc` at the
22 /// start of a haystack. This will remain true, even if the regex engine
23 /// only supported unanchored searches.
25 /// Support only anchored searches. Requesting an unanchored search will
31 pub(crate) fn from_bytes(
33 ) -> Result
<(StartKind
, usize), DeserializeError
> {
34 wire
::check_slice_len(slice
, size_of
::<u32>(), "start kind bytes")?
;
35 let (n
, nr
) = wire
::try_read_u32(slice
, "start kind integer")?
;
37 0 => Ok((StartKind
::Both
, nr
)),
38 1 => Ok((StartKind
::Unanchored
, nr
)),
39 2 => Ok((StartKind
::Anchored
, nr
)),
40 _
=> Err(DeserializeError
::generic("unrecognized start kind")),
44 pub(crate) fn write_to
<E
: Endian
>(
47 ) -> Result
<usize, SerializeError
> {
48 let nwrite
= self.write_to_len();
49 if dst
.len() < nwrite
{
50 return Err(SerializeError
::buffer_too_small("start kind"));
54 StartKind
::Unanchored
=> 1,
55 StartKind
::Anchored
=> 2,
61 pub(crate) fn write_to_len(&self) -> usize {
65 #[cfg_attr(feature = "perf-inline", inline(always))]
66 pub(crate) fn has_unanchored(&self) -> bool
{
67 matches
!(*self, StartKind
::Both
| StartKind
::Unanchored
)
70 #[cfg_attr(feature = "perf-inline", inline(always))]
71 pub(crate) fn has_anchored(&self) -> bool
{
72 matches
!(*self, StartKind
::Both
| StartKind
::Anchored
)