reifydb_testing/util/
mod.rs1pub mod wait;
13
14use std::{error::Error, ops::Bound};
15
16use reifydb_core::util::encoding::binary::decode_binary;
17use reifydb_type::util::cowvec::CowVec;
18
19type KeyRange = (Bound<CowVec<u8>>, Bound<CowVec<u8>>);
20
21pub fn parse_key_range(s: &str) -> Result<KeyRange, Box<dyn Error>> {
22 let mut bound = (Bound::<CowVec<u8>>::Unbounded, Bound::<CowVec<u8>>::Unbounded);
23
24 if let Some(dot_pos) = s.find("..") {
25 let start_part = &s[..dot_pos];
26 let end_part = &s[dot_pos + 2..];
27
28 if !start_part.is_empty() {
29 bound.0 = Bound::Included(CowVec::new(decode_binary(start_part)));
30 }
31
32 if let Some(end_str) = end_part.strip_prefix('=') {
33 if !end_str.is_empty() {
34 bound.1 = Bound::Included(CowVec::new(decode_binary(end_str)));
35 }
36 } else if !end_part.is_empty() {
37 bound.1 = Bound::Excluded(CowVec::new(decode_binary(end_part)));
38 }
39
40 Ok(bound)
41 } else {
42 Err(format!("invalid range {s}").into())
43 }
44}