#[repr(transparent)]
pub struct SerializedDb<'a>(pub DbAllocation<'a>);

Tuple Fields§

§0: DbAllocation<'a>

Implementations§

source§

impl SerializedDb<'static>

source§

impl<'a> SerializedDb<'a>

source

pub fn extract_db_info(&self) -> Result<DbInfo, HyperscanRuntimeError>

 #[cfg(feature = "compiler")]
 fn main() -> Result<(), hyperscan::error::HyperscanError> {
   use hyperscan::{expression::*, flags::*};

   let expr: Expression = "a+".parse()?;
   let serialized_db = expr.compile(Flags::UTF8, Mode::BLOCK)?.serialize()?;
   let info = serialized_db.extract_db_info()?;
   assert_eq!(info.as_str(), "Version: 5.4.2 Features: AVX2 Mode: BLOCK");
   Ok(())
 }
source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn deserialize_db(&self) -> Result<Database, HyperscanRuntimeError>

source

pub fn deserialized_size(&self) -> Result<usize, HyperscanRuntimeError>

Return the size of the allocation necessary for a subsequent call to Self::deserialize_db_at().

source

pub unsafe fn deserialize_db_at( &self, db: *mut NativeDb ) -> Result<(), HyperscanRuntimeError>

Like Self::deserialize_db(), but points into an existing allocation instead of making a new allocation through the allocator from crate::alloc::set_db_allocator()!

Safety: db must point to an allocation at least Self::deserialized_size() in size!

 #[cfg(feature = "compiler")]
 fn main() -> Result<(), hyperscan::error::HyperscanError> {
   use hyperscan::{expression::*, flags::*, matchers::{*, contiguous_slice::*}, database::*};
   use std::mem;

   let expr: Expression = "a+".parse()?;
   let serialized_db = expr.compile(Flags::SOM_LEFTMOST, Mode::BLOCK)?.serialize()?;

   // Allocate a vector with sufficient capacity for the deserialized db:
   let mut db_data: Vec<u8> = Vec::with_capacity(serialized_db.deserialized_size()?);
   let db = unsafe {
     let db_ptr: *mut NativeDb = mem::transmute(db_data.as_mut_ptr());
     serialized_db.deserialize_db_at(db_ptr)?;
     // Wrap in ManuallyDrop to avoid freeing memory owned by the `db_data` vector.
     mem::ManuallyDrop::new(Database::from_native(db_ptr))
   };

   let mut scratch = db.allocate_scratch()?;

   let mut matches: Vec<&str> = Vec::new();
   scratch
     .scan_sync(&db, "aardvark".into(), |Match { source, ..}| {
       matches.push(unsafe { source.as_str() });
       MatchResult::Continue
     })?;
   assert_eq!(&matches, &["a", "aa", "a"]);
   Ok(())
 }

Trait Implementations§

source§

impl<'a> Debug for SerializedDb<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for SerializedDb<'a>

§

impl<'a> Send for SerializedDb<'a>

§

impl<'a> Sync for SerializedDb<'a>

§

impl<'a> Unpin for SerializedDb<'a>

§

impl<'a> UnwindSafe for SerializedDb<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.