From d26db33422b720822b9b24b99ddadc3ffd36d752 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Wed, 13 Jan 2021 11:20:21 -0300 Subject: Finalize Holder design (hopefully) --- src/lib.rs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 9e84de1..f41b4c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,12 +5,41 @@ mod vm; pub use pattern::Pattern; -// TODO +// TODO investigate if this should be PatternTypes: Default +/// Defines the types and operations used for matching. pub trait PatternTypes { /// The value type. type Value; - type Iter; + + /// 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 + '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> { + // 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 -pub type Predicate = dyn (Fn(&::Value) -> bool) + Send + Sync; +type Predicate = dyn (Fn(&::Value) -> bool) + Send + Sync; -- cgit 1.4.1