reifydb_testing/util/
mod.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4// This file includes and modifies code from the toydb project (https://github.com/erikgrinaker/toydb),
5// originally licensed under the Apache License, Version 2.0.
6// Original copyright:
7//   Copyright (c) 2024 Erik Grinaker
8//
9// The original Apache License can be found at:
10//   http://www.apache.org/licenses/LICENSE-2.0
11
12pub mod wait;
13
14use std::{error::Error, ops::Bound};
15
16use reifydb_core::{CowVec, util::encoding::binary::decode_binary};
17
18/// Parses an binary key range, using Rust range syntax.
19pub fn parse_key_range(s: &str) -> Result<(Bound<CowVec<u8>>, Bound<CowVec<u8>>), Box<dyn Error>> {
20	let mut bound = (Bound::<CowVec<u8>>::Unbounded, Bound::<CowVec<u8>>::Unbounded);
21
22	if let Some(dot_pos) = s.find("..") {
23		let start_part = &s[..dot_pos];
24		let end_part = &s[dot_pos + 2..];
25
26		// Parse start bound
27		if !start_part.is_empty() {
28			bound.0 = Bound::Included(decode_binary(start_part));
29		}
30
31		// Parse end bound - check for inclusive marker "="
32		if let Some(end_str) = end_part.strip_prefix('=') {
33			if !end_str.is_empty() {
34				bound.1 = Bound::Included(decode_binary(end_str));
35			}
36		} else if !end_part.is_empty() {
37			bound.1 = Bound::Excluded(decode_binary(end_part));
38		}
39
40		Ok(bound)
41	} else {
42		Err(format!("invalid range {s}").into())
43	}
44}