pub mod wait;
use std::{error::Error, ops::Bound};
use reifydb_core::util::encoding::binary::decode_binary;
use reifydb_value::util::cowvec::CowVec;
type KeyRange = (Bound<CowVec<u8>>, Bound<CowVec<u8>>);
pub fn parse_key_range(s: &str) -> Result<KeyRange, Box<dyn Error>> {
let mut bound = (Bound::<CowVec<u8>>::Unbounded, Bound::<CowVec<u8>>::Unbounded);
if let Some(dot_pos) = s.find("..") {
let start_part = &s[..dot_pos];
let end_part = &s[dot_pos + 2..];
if !start_part.is_empty() {
bound.0 = Bound::Included(CowVec::new(decode_binary(start_part)));
}
if let Some(end_str) = end_part.strip_prefix('=') {
if !end_str.is_empty() {
bound.1 = Bound::Included(CowVec::new(decode_binary(end_str)));
}
} else if !end_part.is_empty() {
bound.1 = Bound::Excluded(CowVec::new(decode_binary(end_part)));
}
Ok(bound)
} else {
Err(format!("invalid range {s}").into())
}
}