Struct hyperscan::database::SerializedDb
source · #[repr(transparent)]pub struct SerializedDb<'a>(pub DbAllocation<'a>);Tuple Fields§
§0: DbAllocation<'a>Implementations§
source§impl SerializedDb<'static>
impl SerializedDb<'static>
pub fn serialize_db(db: &Database) -> Result<Self, HyperscanRuntimeError>
pub fn from_cloned_data(s: &SerializedDb<'_>) -> Self
source§impl<'a> SerializedDb<'a>
impl<'a> SerializedDb<'a>
sourcepub fn extract_db_info(&self) -> Result<DbInfo, HyperscanRuntimeError>
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(())
}pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn deserialize_db(&self) -> Result<Database, HyperscanRuntimeError>
sourcepub fn deserialized_size(&self) -> Result<usize, HyperscanRuntimeError>
pub fn deserialized_size(&self) -> Result<usize, HyperscanRuntimeError>
Return the size of the allocation necessary for a subsequent call to
Self::deserialize_db_at().
sourcepub unsafe fn deserialize_db_at(
&self,
db: *mut NativeDb
) -> Result<(), HyperscanRuntimeError>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more