From a267fda991aaea5613d7abb033cfbc70425dc9a6 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 20 Sep 2024 23:34:35 +0200 Subject: [PATCH] Use same bound type for start and end of iteration --- packages/storey/src/containers/column.rs | 49 +++++++++++++++++++++++- packages/storey/src/containers/mod.rs | 27 ++++++------- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/packages/storey/src/containers/column.rs b/packages/storey/src/containers/column.rs index 577fcb2..b792731 100644 --- a/packages/storey/src/containers/column.rs +++ b/packages/storey/src/containers/column.rs @@ -558,6 +558,7 @@ mod tests { access.push(&2).unwrap(); access.remove(2).unwrap(); + // start and end set assert_eq!( access .bounded_pairs(Some(1), Some(4)) @@ -565,7 +566,6 @@ mod tests { .unwrap(), vec![(1, 42), (3, 1)] ); - assert_eq!( access .bounded_keys(Some(1), Some(4)) @@ -573,7 +573,6 @@ mod tests { .unwrap(), vec![1, 3] ); - assert_eq!( access .bounded_values(Some(1), Some(4)) @@ -581,5 +580,51 @@ mod tests { .unwrap(), vec![42, 1] ); + + // end unset + assert_eq!( + access + .bounded_pairs(Some(1), None) + .collect::, _>>() + .unwrap(), + vec![(1, 42), (3, 1), (4, 2)] + ); + assert_eq!( + access + .bounded_keys(Some(1), None) + .collect::, _>>() + .unwrap(), + vec![1, 3, 4] + ); + assert_eq!( + access + .bounded_values(Some(1), None) + .collect::, _>>() + .unwrap(), + vec![42, 1, 2] + ); + + // start unset + assert_eq!( + access + .bounded_pairs(None, Some(4)) + .collect::, _>>() + .unwrap(), + vec![(0, 1337), (1, 42), (3, 1)] + ); + assert_eq!( + access + .bounded_keys(None, Some(4)) + .collect::, _>>() + .unwrap(), + vec![0, 1, 3] + ); + assert_eq!( + access + .bounded_values(None, Some(4)) + .collect::, _>>() + .unwrap(), + vec![1337, 42, 1] + ); } } diff --git a/packages/storey/src/containers/mod.rs b/packages/storey/src/containers/mod.rs index a24bc98..dbc469c 100644 --- a/packages/storey/src/containers/mod.rs +++ b/packages/storey/src/containers/mod.rs @@ -125,14 +125,13 @@ pub trait IterableAccessor: Sized { /// in turn means the entries found between two string keys may not be the expected ones. pub trait BoundedIterableAccessor: IterableAccessor { /// Iterate over key-value pairs in this collection, respecting the given bounds. - fn bounded_pairs( + fn bounded_pairs( &self, - start: Option, - end: Option, + start: Option, + end: Option, ) -> StorableIter<'_, Self::Storable, Self::Storage> where - S: BoundFor, - E: BoundFor, + B: BoundFor, { let start = start.map(|b| b.into_bytes()); let end = end.map(|b| b.into_bytes()); @@ -144,14 +143,13 @@ pub trait BoundedIterableAccessor: IterableAccessor { } /// Iterate over keys in this collection, respecting the given bounds. - fn bounded_keys( + fn bounded_keys( &self, - start: Option, - end: Option, + start: Option, + end: Option, ) -> StorableKeys<'_, Self::Storable, Self::Storage> where - S: BoundFor, - E: BoundFor, + B: BoundFor, { let start = start.map(|b| b.into_bytes()); let end = end.map(|b| b.into_bytes()); @@ -163,14 +161,13 @@ pub trait BoundedIterableAccessor: IterableAccessor { } /// Iterate over values in this collection, respecting the given bounds. - fn bounded_values( + fn bounded_values( &self, - start: Option, - end: Option, + start: Option, + end: Option, ) -> StorableValues<'_, Self::Storable, Self::Storage> where - S: BoundFor, - E: BoundFor, + B: BoundFor, { let start = start.map(|b| b.into_bytes()); let end = end.map(|b| b.into_bytes());