pub struct DatabaseRef<T>(_, _);
Expand description

A borrowed reference to a Database.

Implementations

Provides the id of compiled mode of the given database.

Provides the name of compiled mode of the given database.

Provides the size of the given database in bytes.

Utility function providing information about a database.

Serialize a pattern database to a stream of bytes.

Examples
let pattern: Pattern = r"/foo(bar)+/i".parse().unwrap();
let db: BlockDatabase = pattern.left_most().build().unwrap();
let buf = db.serialize().unwrap();
assert!(buf.len() > 0);
assert!(buf.size().unwrap() > 0);
println!("database ({}) need {} bytes", buf.info().unwrap(), buf.size().unwrap());

let deserialized_db: BlockDatabase = buf.deserialize().unwrap();
let mut s = deserialized_db.alloc_scratch().unwrap();
let mut matches = Vec::new();

deserialized_db.scan("hello foobar!", &mut s, |id, from, to, _flags| {
    matches.push(from..to);
    Matching::Continue
}).unwrap();

assert_eq!(matches, vec![6..12]);

Reconstruct a pattern database from a stream of bytes previously generated by DatabaseRef::serialize() at a given memory location.

The block (non-streaming) regular expression scanner.

This is the function call in which the actual pattern matching takes place for block-mode pattern databases.

Examples
let db: BlockDatabase = pattern! {"test"; CASELESS | SOM_LEFTMOST}.build().unwrap();
let s = db.alloc_scratch().unwrap();
let mut matches = vec![];

db.scan("foo test bar", &s, |_, from, to, _| {
    matches.push(from..to);
    Matching::Continue
}).unwrap();

assert_eq!(matches, vec![4..8]);

The vectored regular expression scanner.

This is the function call in which the actual pattern matching takes place for vectoring-mode pattern databases.

Examples
let db: VectoredDatabase = pattern!{"test"; CASELESS|SOM_LEFTMOST}.build().unwrap();
let s = db.alloc_scratch().unwrap();

let mut matches = vec![];

db.scan(vec!["foo", "test", "bar"], &s, |id, from, to, _| {
    matches.push(from..to);
    Matching::Continue
}).unwrap();

assert_eq!(matches, vec![3..7]);

Pattern matching takes place for stream-mode pattern databases.

Examples
const SCAN_BUF_SIZE: usize = 4096;
let mut buf = String::from_utf8(vec![b'x'; SCAN_BUF_SIZE - 2]).unwrap();

buf.push_str("baaab");

let db: StreamingDatabase = pattern! { "a+"; SOM_LEFTMOST }.build().unwrap();
let s = db.alloc_scratch().unwrap();
let mut cur = Cursor::new(buf.as_bytes());
let mut matches = vec![];

db.scan(&mut cur, &s, |_, from, to, _| {
    matches.push((from, to));

    Matching::Continue
})
.unwrap();

assert_eq!(matches, vec![(4095, 4096), (4095, 4097), (4095, 4098)]);

Allocate a “scratch” space for use by Hyperscan.

Reallocate a “scratch” space for use by Hyperscan.

👎Deprecated:

use alloc_scratch instead

Allocate a “scratch” space for use by Hyperscan.

👎Deprecated:

use realloc_scratch instead

Reallocate a “scratch” space for use by Hyperscan.

Provides the size of the stream state allocated by a single stream opened against the given database.

Open and initialise a stream.

Decompresses a compressed representation created by StreamRef::compress() into a new stream.

Note: buf must correspond to a complete compressed representation created by StreamRef::compress() of a stream that was opened against db. It is not always possible to detect misuse of this API and behaviour is undefined if these properties are not satisfied.

Examples
let db: StreamingDatabase = pattern! {"test"; SOM_LEFTMOST}.build().unwrap();

let s = db.alloc_scratch().unwrap();
let st = db.open_stream().unwrap();

let mut matches = vec![];

let mut callback = |_, from, to, _| {
    matches.push((from, to));

    Matching::Continue
};

st.scan("foo t", &s, &mut callback).unwrap();
st.scan("es", &s, &mut callback).unwrap();

let mut buf = [0; 8192];
let len = st.compress(&mut buf).unwrap();
st.close(&s, Matching::Terminate).unwrap();

let st2 = db.expand_stream(&buf[..len]).unwrap();
st2.scan("t bar", &s, &mut callback).unwrap();
st2.close(&s, &mut callback).unwrap();

assert_eq!(matches, vec![(4, 8)]);

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
The raw C type.
Constructs a shared instance of this type from its raw type. Read more
Constructs a mutable reference of this type from its raw type. Read more
Returns a raw pointer to the wrapped value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.