1use anyhow::bail;
2#[allow(clippy::type_complexity)]
9pub(crate) fn convert_bounds(
10 range: impl std::ops::RangeBounds<Vec<u8>>,
11) -> anyhow::Result<(
12 impl std::ops::RangeBounds<Vec<u8>>,
13 (Option<Vec<u8>>, Option<Vec<u8>>),
14)> {
15 let start = match range.start_bound() {
16 std::ops::Bound::Included(v) => Some(v.clone()),
17 std::ops::Bound::Excluded(v) => Some(v.clone()),
18 std::ops::Bound::Unbounded => None,
19 };
20
21 let end = match range.end_bound() {
22 std::ops::Bound::Included(_) => bail!("included end bound not supported"),
23 std::ops::Bound::Excluded(v) => Some(v.clone()),
24 std::ops::Bound::Unbounded => None,
25 };
26
27 if let (Some(k_start), Some(k_end)) = (&start, &end) {
28 if k_start > k_end {
29 bail!("lower bound is greater than upper bound")
30 }
31 }
32
33 Ok((range, (start, end)))
34}