pub struct Database(/* private fields */);

Implementations§

source§

impl Database

source

pub const unsafe fn from_native(p: *mut NativeDb) -> Self

source

pub fn as_ref_native(&self) -> &NativeDb

source

pub fn as_mut_native(&mut self) -> &mut NativeDb

source

pub fn allocate_scratch(&self) -> Result<Scratch, HyperscanRuntimeError>

source

pub fn compile( expression: &Expression, flags: Flags, mode: Mode, platform: Option<&Platform> ) -> Result<Self, HyperscanCompileError>

Available on crate feature compiler only.
 use hyperscan::{expression::*, flags::*, database::*, matchers::*};

 let expr: Expression = "(he)ll".parse()?;
 let db = Database::compile(&expr, Flags::UTF8, Mode::BLOCK, None)?;

 let mut scratch = db.allocate_scratch()?;

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

pub fn compile_literal( literal: &Literal, flags: Flags, mode: Mode, platform: Option<&Platform> ) -> Result<Self, HyperscanCompileError>

Available on crate feature compiler only.
 use hyperscan::{expression::*, flags::*, database::*, matchers::*};

 let expr: Literal = "he\0ll".parse()?;
 let db = Database::compile_literal(&expr, Flags::default(), Mode::BLOCK, None)?;

 let mut scratch = db.allocate_scratch()?;

 let mut matches: Vec<&str> = Vec::new();
 scratch
   .scan_sync(&db, "he\0llo".into(), |m| {
     matches.push(unsafe { m.source.as_str() });
     MatchResult::Continue
   })?;
 assert_eq!(&matches, &["he\0ll"]);
source

pub fn compile_multi( expression_set: &ExpressionSet<'_>, mode: Mode, platform: Option<&Platform> ) -> Result<Self, HyperscanCompileError>

Available on crate feature compiler only.
 use hyperscan::{expression::*, flags::*, database::*, matchers::*};

 let a_expr: Expression = "a+".parse()?;
 let b_expr: Expression = "b+".parse()?;

 // Example of providing ExprExt info (not available in ::compile()!):
 let ext = ExprExt::from_min_length(1);

 let expr_set = ExpressionSet::from_exprs([&a_expr, &b_expr])
   .with_flags([Flags::UTF8, Flags::UTF8])
   .with_ids([ExprId(1), ExprId(2)])
   .with_exts([None, Some(&ext)]);

 let db = Database::compile_multi(&expr_set, Mode::BLOCK, None)?;

 let mut scratch = db.allocate_scratch()?;

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

 matches.clear();
 scratch
   .scan_sync(&db, "imbibe".into(), |m| {
     matches.push(unsafe { m.source.as_str() });
     MatchResult::Continue
   })?;
 assert_eq!(&matches, &["imb", "imbib"]);
source

pub fn compile_multi_literal( literal_set: &LiteralSet<'_>, mode: Mode, platform: Option<&Platform> ) -> Result<Self, HyperscanCompileError>

Available on crate feature compiler only.
 use hyperscan::{expression::*, flags::*, database::*, matchers::{*, contiguous_slice::*}};

 let hell_lit: Literal = "he\0ll".parse()?;
 let free_lit: Literal = "fr\0e\0e".parse()?;
 let lit_set = LiteralSet::from_lits([&hell_lit, &free_lit])
   .with_flags([Flags::default(), Flags::default()])
   .with_ids([ExprId(2), ExprId(1)]);

 let db = Database::compile_multi_literal(&lit_set, Mode::BLOCK, None)?;

 let mut scratch = db.allocate_scratch()?;

 let mut matches: Vec<(u32, &str)> = Vec::new();
 scratch
   .scan_sync(
     &db,
     "he\0llo".into(),
     |Match { id: ExpressionIndex(id), source, .. }| {
       matches.push((id, unsafe { source.as_str() }));
       MatchResult::Continue
     })?;
 assert_eq!(&matches, &[(2, "he\0ll")]);

 matches.clear();
 scratch
   .scan_sync(
     &db,
     "fr\0e\0edom".into(),
     |Match { id: ExpressionIndex(id), source, .. }| {
       matches.push((id, unsafe { source.as_str() }));
       MatchResult::Continue
     })?;
 assert_eq!(&matches, &[(1, "fr\0e\0e")]);
source

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

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

   let expr: Expression = "a+".parse()?;
   let db = expr.compile(Flags::UTF8, Mode::BLOCK)?;
   let db_size = db.database_size()?;

   // Size may vary across architectures:
   assert_eq!(db_size, 936);
   assert!(db_size > 500);
   assert!(db_size < 2000);
   Ok(())
 }
source

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

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

   let expr: Expression = "a+".parse()?;
   let db = expr.compile(Flags::UTF8, Mode::STREAM)?;
   let stream_size = db.stream_size()?;

   // Size may vary across architectures:
   assert_eq!(stream_size, 18);
   assert!(stream_size > 10);
   assert!(stream_size < 20);
   Ok(())
 }
source

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

source

pub fn serialize(&self) -> Result<SerializedDb<'static>, HyperscanRuntimeError>

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

   let expr: Expression = "a+".parse()?;
   let db = expr.compile(Flags::SOM_LEFTMOST, Mode::BLOCK)?.serialize()?.deserialize_db()?;
   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(())
 }
source

pub unsafe fn try_drop(&mut self) -> Result<(), HyperscanRuntimeError>

Trait Implementations§

source§

impl Debug for Database

source§

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

Formats the value using the given formatter. Read more
source§

impl Drop for Database

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for Database

source§

impl Sync for Database

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