pub trait Engine {
// Required methods
fn count<I>(&self, input: &I) -> Result<MatchCount, EngineError>
where I: Input;
fn indices<I, S>(&self, input: &I, sink: &mut S) -> Result<(), EngineError>
where I: Input,
S: Sink<MatchIndex>;
fn approximate_spans<I, S>(
&self,
input: &I,
sink: &mut S
) -> Result<(), EngineError>
where I: Input,
S: Sink<MatchSpan>;
fn matches<I, S>(&self, input: &I, sink: &mut S) -> Result<(), EngineError>
where I: Input,
S: Sink<Match>;
}
Expand description
An engine that can run its query on a given input.
Required Methods§
sourcefn count<I>(&self, input: &I) -> Result<MatchCount, EngineError>where
I: Input,
fn count<I>(&self, input: &I) -> Result<MatchCount, EngineError>where
I: Input,
Find the number of matches on the given Input
.
The result is equivalent to using matches
and counting the matches,
but in general is much more time and memory efficient.
§Errors
An appropriate EngineError
is returned if the JSON input is malformed
and the syntax error is detected.
Please note that detecting malformed JSONs is not guaranteed. Some glaring errors like mismatched braces or double quotes are raised, but in general the result of an engine run on an invalid JSON is undefined. It is guaranteed that the computation terminates and does not panic.
sourcefn indices<I, S>(&self, input: &I, sink: &mut S) -> Result<(), EngineError>
fn indices<I, S>(&self, input: &I, sink: &mut S) -> Result<(), EngineError>
Find the starting indices of matches on the given Input
and write them to the Sink
.
The result is equivalent to using matches
and extracting the
[Match::span.start_idx
],
but in general is much more time and memory efficient.
§Errors
An appropriate EngineError
is returned if the JSON input is malformed
and the syntax error is detected.
Please note that detecting malformed JSONs is not guaranteed. Some glaring errors like mismatched braces or double quotes are raised, but in general the result of an engine run on an invalid JSON is undefined. It is guaranteed that the computation terminates and does not panic.
sourcefn approximate_spans<I, S>(
&self,
input: &I,
sink: &mut S
) -> Result<(), EngineError>
fn approximate_spans<I, S>( &self, input: &I, sink: &mut S ) -> Result<(), EngineError>
Find the approximate spans of matches on the given Input
and write them to the Sink
.
“Approximate” means that the ends of spans are not guaranteed to be located exactly at the end of a match, but may include trailing whitespace. Importantly, it may be beyond the rigidly-defined length of the input, as the engine is allowed to pad the input with whitespace to help with processing. For the purposes of this API, it is assumed that every character after the logical end of the input is a whitespace character. With that in mind, it is guaranteed that:
- the span start is exact;
- the span encompasses the entire matched value;
- the only characters included after the value are JSON whitespace characters: space (0x20), horizontal tab (0x09), new line (0x0A), carriage return (0x0D).
§Errors
An appropriate EngineError
is returned if the JSON input is malformed
and the syntax error is detected.
Please note that detecting malformed JSONs is not guaranteed. Some glaring errors like mismatched braces or double quotes are raised, but in general the result of an engine run on an invalid JSON is undefined. It is guaranteed that the computation terminates and does not panic.
sourcefn matches<I, S>(&self, input: &I, sink: &mut S) -> Result<(), EngineError>
fn matches<I, S>(&self, input: &I, sink: &mut S) -> Result<(), EngineError>
Find all matches on the given Input
and write them to the Sink
.
§Errors
An appropriate EngineError
is returned if the JSON input is malformed
and the syntax error is detected.
Please note that detecting malformed JSONs is not guaranteed. Some glaring errors like mismatched braces or double quotes are raised, but in general the result of an engine run on an invalid JSON is undefined. It is guaranteed that the computation terminates and does not panic.