pub struct Database(/* private fields */);Implementations§
source§impl Database
impl Database
pub const unsafe fn from_native(p: *mut NativeDb) -> Self
pub fn as_ref_native(&self) -> &NativeDb
pub fn as_mut_native(&mut self) -> &mut NativeDb
pub fn allocate_scratch(&self) -> Result<Scratch, HyperscanRuntimeError>
sourcepub fn compile(
expression: &Expression,
flags: Flags,
mode: Mode,
platform: Option<&Platform>
) -> Result<Self, HyperscanCompileError>
Available on crate feature compiler only.
pub fn compile( expression: &Expression, flags: Flags, mode: Mode, platform: Option<&Platform> ) -> Result<Self, HyperscanCompileError>
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"]);sourcepub fn compile_literal(
literal: &Literal,
flags: Flags,
mode: Mode,
platform: Option<&Platform>
) -> Result<Self, HyperscanCompileError>
Available on crate feature compiler only.
pub fn compile_literal( literal: &Literal, flags: Flags, mode: Mode, platform: Option<&Platform> ) -> Result<Self, HyperscanCompileError>
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"]);sourcepub fn compile_multi(
expression_set: &ExpressionSet<'_>,
mode: Mode,
platform: Option<&Platform>
) -> Result<Self, HyperscanCompileError>
Available on crate feature compiler only.
pub fn compile_multi( expression_set: &ExpressionSet<'_>, mode: Mode, platform: Option<&Platform> ) -> Result<Self, HyperscanCompileError>
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"]);sourcepub fn compile_multi_literal(
literal_set: &LiteralSet<'_>,
mode: Mode,
platform: Option<&Platform>
) -> Result<Self, HyperscanCompileError>
Available on crate feature compiler only.
pub fn compile_multi_literal( literal_set: &LiteralSet<'_>, mode: Mode, platform: Option<&Platform> ) -> Result<Self, HyperscanCompileError>
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")]);sourcepub fn database_size(&self) -> Result<usize, HyperscanRuntimeError>
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(())
}sourcepub fn stream_size(&self) -> Result<usize, HyperscanRuntimeError>
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(())
}pub fn info(&self) -> Result<DbInfo, HyperscanRuntimeError>
sourcepub fn serialize(&self) -> Result<SerializedDb<'static>, HyperscanRuntimeError>
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(())
}pub unsafe fn try_drop(&mut self) -> Result<(), HyperscanRuntimeError>
Trait Implementations§
impl Send for Database
impl Sync for Database
Auto Trait Implementations§
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