plotnik_bytecode/dfa.rs
1//! DFA deserialization for regex predicates.
2//!
3//! Extracted from emit for use by the runtime.
4
5use regex_automata::dfa::sparse::DFA;
6
7/// Deserialize a sparse DFA from bytecode.
8///
9/// # Safety
10/// The bytes must have been produced by `DFA::to_bytes_little_endian()`.
11pub fn deserialize_dfa(bytes: &[u8]) -> Result<DFA<&[u8]>, String> {
12 // SAFETY: We only serialize DFAs we built, and the format is stable
13 // within the same regex-automata version.
14 DFA::from_bytes(bytes)
15 .map(|(dfa, _)| dfa)
16 .map_err(|e| e.to_string())
17}