From 7411260cd370486a6cda5535c84a2e5b1a604e49 Mon Sep 17 00:00:00 2001 From: Mark Giraud Date: Tue, 16 Apr 2024 14:44:13 +0200 Subject: [PATCH] feat: Make get_next/get_prev mor generic such that borrowed forms of keys can be used. --- src/ord/set.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ord/set.rs b/src/ord/set.rs index d8df833..44cc9c3 100644 --- a/src/ord/set.rs +++ b/src/ord/set.rs @@ -449,8 +449,12 @@ where /// assert_eq!(Some(&5), set.get_prev(&6)); /// ``` #[must_use] - pub fn get_prev(&self, key: &A) -> Option<&A> { - self.root.lookup_prev(key).map(|v| &v.0) + pub fn get_prev(&self, k: &BK) -> Option<&A> + where + BK: Ord + ?Sized, + A: Borrow, + { + self.root.lookup_prev(k).map(|v| &v.0) } /// Get the closest larger value in a set to a given value. @@ -469,8 +473,12 @@ where /// assert_eq!(Some(&5), set.get_next(&4)); /// ``` #[must_use] - pub fn get_next(&self, key: &A) -> Option<&A> { - self.root.lookup_next(key).map(|v| &v.0) + pub fn get_next(&self, k: &BK) -> Option<&A> + where + BK: Ord + ?Sized, + A: Borrow, + { + self.root.lookup_next(k).map(|v| &v.0) } /// Test whether a set is a subset of another set, meaning that