Function hyperscan::alloc::set_allocator

source ·
pub fn set_allocator(
    allocator: Arc<impl GlobalAlloc + 'static>
) -> Result<(), HyperscanRuntimeError>
Available on crate feature alloc only.
Expand description
 #[cfg(feature = "compiler")]
 fn main() -> Result<(), hyperscan::error::HyperscanError> {
   use hyperscan::{expression::*, flags::*, matchers::*};
   use std::alloc::System;

   hyperscan::alloc::set_allocator(System.into())?;

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

   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"]);
   Ok(())
 }