use anyhow::bail;
#[allow(clippy::type_complexity)]
pub(crate) fn convert_bounds(
range: impl std::ops::RangeBounds<Vec<u8>>,
) -> anyhow::Result<(
impl std::ops::RangeBounds<Vec<u8>>,
(Option<Vec<u8>>, Option<Vec<u8>>),
)> {
let start = match range.start_bound() {
std::ops::Bound::Included(v) => Some(v.clone()),
std::ops::Bound::Excluded(v) => Some(v.clone()),
std::ops::Bound::Unbounded => None,
};
let end = match range.end_bound() {
std::ops::Bound::Included(_) => bail!("included end bound not supported"),
std::ops::Bound::Excluded(v) => Some(v.clone()),
std::ops::Bound::Unbounded => None,
};
if let (Some(k_start), Some(k_end)) = (&start, &end) {
if k_start > k_end {
bail!("lower bound is greater than upper bound")
}
}
Ok((range, (start, end)))
}