GenericBinaryPattern

Struct GenericBinaryPattern 

Source
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>

Source

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.

Source

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.

Source

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<'_>

Source§

fn atoms(&self) -> &[Atom]

Retrieves the list of atoms within this binary pattern. Read more
Source§

fn byte_sequence(&self) -> &[u8]

Retrieves the byte sequence referenced by the atoms. Read more
Source§

fn save_len(&self) -> usize

Returns an upper bound for the length of the save stack. Read more
Source§

fn cursor_len(&self) -> usize

Returns an upper bound for the length of the cursor stack. Read more
Source§

impl<'a> Clone for GenericBinaryPattern<'a>

Source§

fn clone(&self) -> GenericBinaryPattern<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for GenericBinaryPattern<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.