Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wizer/benches/regex-bench/src/lib.rs
2460 views
1
use regex::Regex;
2
use std::sync::LazyLock;
3
4
/// A regex that matches numbers that start with "1".
5
static REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^1\d*$").unwrap());
6
7
#[unsafe(export_name = "wizer-initialize")]
8
pub extern "C" fn init() {
9
LazyLock::force(&REGEX);
10
}
11
12
#[unsafe(export_name = "run")]
13
pub extern "C" fn run(ptr: *mut u8, len: usize) -> i32 {
14
let s = unsafe {
15
let slice = std::slice::from_raw_parts(ptr, len);
16
std::str::from_utf8(slice).unwrap()
17
};
18
REGEX.is_match(&s) as u8 as i32
19
}
20
21