The Type enum can be replaced with a bitflag struct (using the bitflags crate). This will remove the need for some values, such as SeparatorReturn, which is strictly a combination of the Separator and Return variants. Additionally, some other State attributes could be added to a bitflags struct, simplifying things quite a bit.
I think the struct definition would look something like this:
The actual str currently stored in the Word variant will need to be stored as an attribute within the State instead. Without having the store the str directly, we could even combine the WORD and EXCEPTION flags into a single MATCH flag and use the presence of the str to decide whether it is a word or exception match. This isn't strictly necessary, since we have enough bits to have the two options be distinct, and having the two states be distinct will make matching easier.
The
Type
enum can be replaced with a bitflag struct (using thebitflags
crate). This will remove the need for some values, such asSeparatorReturn
, which is strictly a combination of theSeparator
andReturn
variants. Additionally, some otherState
attributes could be added to a bitflags struct, simplifying things quite a bit.I think the struct definition would look something like this:
The actual
str
currently stored in theWord
variant will need to be stored as an attribute within theState
instead. Without having the store thestr
directly, we could even combine theWORD
andEXCEPTION
flags into a singleMATCH
flag and use the presence of thestr
to decide whether it is a word or exception match. This isn't strictly necessary, since we have enough bits to have the two options be distinct, and having the two states be distinct will make matching easier.