blob: f41b4c6f26e9093a1e73f82153109bbe9aeba7b7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
pub mod errors;
mod parser;
mod pattern;
mod vm;
pub use pattern::Pattern;
// TODO investigate if this should be PatternTypes: Default
/// Defines the types and operations used for matching.
pub trait PatternTypes {
/// The value type.
type Value;
/// The owned key type. May be uninhabited.
// TODO replace with GATs.
type Key;
/// Returns an iterator over key-value pairs contained within an item, or
/// None if this operation is unsupported for the given value.
fn pairs<'b>(
item: &'b Self::Value
) -> Option<Box<dyn Iterator<Item=(&'b Self::Value, &'b Self::Value)> + 'b>> {
// TODO remove these default impls that only exist for testing purposes
let x = None;
Some(Box::new(x.into_iter()))
}
/// Returns an optional key-value pair keyed by the given key, or None if
/// this operation is unsupported for the given value.
fn get<'a, 'b>(
item: &'b Self::Value,
key: &'a str
) -> Option<Option<(&'b Self::Value, &'b Self::Value)>> {
// TODO remove these default impls that only exist for testing purposes
Some(None)
}
/// Returns whether two values are the same/equivalent. This must provide
/// the same guarantees as PartialEq. In fact, this is a replacement for
/// PartialEq for cases where it's not possible to just use PartialEq.
fn matches(left: &Self::Value, right: &Self::Value) -> bool;
}
// TODO
type Predicate<T> = dyn (Fn(&<T as PatternTypes>::Value) -> bool) + Send + Sync;
|