pub struct GenericBinaryPattern<'a> { /* private fields */ }Expand description
A flexible implementation of the BinaryPattern interface supporting both borrowed and owned data.
This struct uses alloc::borrow::Cow for both the Atom array and the byte sequence,
allowing it to either borrow data without allocation or own it when necessary.
This design makes it suitable for both compile-time defined and runtime-parsed patterns.
§Example
let atoms = &[Atom::ByteSequence { seq_start: 0x00, seq_end: 0x01 }];
let bytes = &[0x90];
// Borrowed (no allocation)
let borrowed = GenericBinaryPattern::new(atoms, bytes);
// Owned (allocating)
let owned = GenericBinaryPattern::new(vec![Atom::ByteSequence { seq_start: 0x00, seq_end: 0x01 }], vec![0x90]);Implementations§
Source§impl<'a> GenericBinaryPattern<'a>
impl<'a> GenericBinaryPattern<'a>
Sourcepub fn new(
atoms: impl Into<Cow<'a, [Atom]>>,
byte_sequence: impl Into<Cow<'a, [u8]>>,
) -> Self
pub fn new( atoms: impl Into<Cow<'a, [Atom]>>, byte_sequence: impl Into<Cow<'a, [u8]>>, ) -> Self
Creates a new GenericBinaryPattern from borrowed or owned data.
This constructor accepts any type that can be converted into a Cow,
such as slices or vectors.
Borrowed inputs (&[Atom], &[u8]) avoid allocation, while owned inputs
(Vec<Atom>, Vec<u8>) store the data internally.
Sourcepub const fn new_const(atoms: &'a [Atom], byte_sequence: &'a [u8]) -> Self
pub const fn new_const(atoms: &'a [Atom], byte_sequence: &'a [u8]) -> Self
Creates a borrowed GenericBinaryPattern from static references.
This constructor is const and does not perform any heap allocation.
It is ideal for defining patterns that reference constant or static data.
Sourcepub fn into_owned(self) -> GenericBinaryPattern<'static>
pub fn into_owned(self) -> GenericBinaryPattern<'static>
Converts the pattern into an owned version with a 'static lifetime.
Any borrowed data is cloned into owned memory, ensuring that the returned
pattern no longer depends on the original lifetimes.
This is useful when the pattern needs to outlive temporary references.
Trait Implementations§
Source§impl BinaryPattern for GenericBinaryPattern<'_>
impl BinaryPattern for GenericBinaryPattern<'_>
Source§fn byte_sequence(&self) -> &[u8]
fn byte_sequence(&self) -> &[u8]
Source§fn save_len(&self) -> usize
fn save_len(&self) -> usize
Source§fn cursor_len(&self) -> usize
fn cursor_len(&self) -> usize
Source§impl<'a> Clone for GenericBinaryPattern<'a>
impl<'a> Clone for GenericBinaryPattern<'a>
Source§fn clone(&self) -> GenericBinaryPattern<'a>
fn clone(&self) -> GenericBinaryPattern<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more