Skip to content

Commit

Permalink
remove option interface for list and dequeue iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek-sha committed Aug 19, 2024
1 parent 29b002d commit d5f6738
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
18 changes: 8 additions & 10 deletions src/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ where
pub fn iter<'a, Q: ?Sized + Encode>(
&'a self,
list_key: &Q,
) -> impl Iterator<Item = Result<Option<(K, V)>>> + 'a
) -> impl Iterator<Item = Result<(K, V)>> + 'a
where
L: Borrow<Q>,
{
Expand All @@ -405,7 +405,7 @@ where
Ok((k, v)) => {
let key = from_bytes::<K>(&k)?;
let val = from_bytes::<V>(&v)?;
Ok(Some((key, val)))
Ok((key, val))
}
})
}
Expand All @@ -414,7 +414,7 @@ where
pub fn iter_backwards<'a, Q: ?Sized + Encode>(
&'a self,
list_key: &Q,
) -> impl Iterator<Item = Result<Option<(K, V)>>> + 'a
) -> impl Iterator<Item = Result<(K, V)>> + 'a
where
L: Borrow<Q>,
{
Expand All @@ -426,7 +426,7 @@ where
Ok((k, v)) => {
let key = from_bytes::<K>(&k)?;
let val = from_bytes::<V>(&v)?;
Ok(Some((key, val)))
Ok((key, val))
}
})
}
Expand Down Expand Up @@ -611,29 +611,27 @@ where
pub fn iter<'a, Q: ?Sized + Encode>(
&'a self,
list_key: &Q,
) -> impl Iterator<Item = Result<Option<V>>> + 'a
) -> impl Iterator<Item = Result<V>> + 'a
where
L: Borrow<Q>,
{
self.list.iter(list_key).map(|res| match res {
Err(e) => Err(e),
Ok(None) => Ok(None),
Ok(Some((_, v))) => Ok(Some(v)),
Ok((_, v)) => Ok(v),
})
}

/// See [CandyTypedList::iter_backwards]
pub fn iter_backwards<'a, Q: ?Sized + Encode>(
&'a self,
list_key: &Q,
) -> impl Iterator<Item = Result<Option<V>>> + 'a
) -> impl Iterator<Item = Result<V>> + 'a
where
L: Borrow<Q>,
{
self.list.iter_backwards(list_key).map(|res| match res {
Err(e) => Err(e),
Ok(None) => Ok(None),
Ok(Some((_, v))) => Ok(Some(v)),
Ok((_, v)) => Ok(v),
})
}
}
8 changes: 4 additions & 4 deletions tests/test_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn test_typed_lists() -> Result<()> {

let items = typed
.iter("texas")
.map(|res| res.unwrap().unwrap().1)
.map(|res| res.unwrap().1)
.collect::<Vec<_>>();
assert_eq!(items, vec![2005, 2009, 2008]);

Expand Down Expand Up @@ -313,14 +313,14 @@ fn test_typed_queue() -> Result<()> {

let items = queue
.iter("orders")
.map(|res| res.unwrap().unwrap())
.map(|res| res.unwrap())
.collect::<Vec<_>>();

assert_eq!(items, vec![105, 104, 103, 100, 101, 102]);

let items = queue
.iter_backwards("orders")
.map(|res| res.unwrap().unwrap())
.map(|res| res.unwrap())
.collect::<Vec<_>>();

assert_eq!(items, vec![102, 101, 100, 103, 104, 105]);
Expand Down Expand Up @@ -414,7 +414,7 @@ fn test_typed_promote() -> Result<()> {
let items = || {
typed
.iter("mylist")
.map(|res| res.unwrap().unwrap().0)
.map(|res| res.unwrap().0)
.collect::<Vec<_>>()
};

Expand Down

0 comments on commit d5f6738

Please sign in to comment.