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

Wrapper for a serialized form of a Database.

Tuple Fields§

§0: DbAllocation<'a>

This serialization data can be sourced from a variety of places.

Implementations§

source§

impl<'a> SerializedDb<'a>

Methods available to all types of allocations.

source

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

Deserialize into a new db allocation.

This will make a new allocation through the allocator from crate::alloc::set_db_allocator().

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

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

   // Note that the expected deserialized size is the same
   // as the resulting in-memory database size:
   assert_eq!(db.database_size()?, serialized_db.deserialized_size()?);
   Ok(())
 }
source

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

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<(), VectorscanRuntimeError>

Like Self::deserialize_db(), but points into an existing allocation instead of making a new allocation.

Safety

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

 #[cfg(feature = "compiler")]
 fn main() -> Result<(), vectorscan::error::VectorscanError> {
   use vectorscan::{expression::*, flags::*, 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))
   };
   // Note that the expected deserialized size is the same
   // as the resulting in-memory database size:
   assert_eq!(db.database_size()?, serialized_db.deserialized_size()?);
   Ok(())
 }
source

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

Extract metadata about the serialized database into a new string allocation.

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

   let expr: Expression = "a+".parse()?;
   let serialized_db = expr.compile(Flags::default(), Mode::BLOCK)?.serialize()?;
   let info = serialized_db.extract_db_info()?;
   assert_eq!(info.as_str(), "Version: 5.4.11 Features: AVX2 Mode: BLOCK");
   // Info is the same as would have been provided from deserializing:
   assert_eq!(info, serialized_db.deserialize_db()?.info()?);
   Ok(())
 }
source§

impl SerializedDb<'static>

Owned Allocations

Methods that produce new owned ('static) allocations.

A Clone impl is also available for such owned allocations.

source

pub fn serialize_db(db: &Database) -> Result<Self, VectorscanRuntimeError>

Write a serialized representation of db into a newly allocated region of memory.

source

pub fn from_cloned_data(s: &SerializedDb<'_>) -> Self

Allocate a new region of memory and copy over the referenced data from s.

Trait Implementations§

source§

impl Clone for SerializedDb<'static>

source§

fn clone(&self) -> Self

Returns a copy 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 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> ToOwned for T
where T: Clone,

§

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

§

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.