Skip to main content

reifydb_testing/util/
mod.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
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::util::encoding::binary::decode_binary;
17use reifydb_type::util::cowvec::CowVec;
18
19/// Parses an binary key range, using Rust range syntax.
20pub fn parse_key_range(s: &str) -> Result<(Bound<CowVec<u8>>, Bound<CowVec<u8>>), Box<dyn Error>> {
21	let mut bound = (Bound::<CowVec<u8>>::Unbounded, Bound::<CowVec<u8>>::Unbounded);
22
23	if let Some(dot_pos) = s.find("..") {
24		let start_part = &s[..dot_pos];
25		let end_part = &s[dot_pos + 2..];
26
27		// Parse start bound
28		if !start_part.is_empty() {
29			bound.0 = Bound::Included(decode_binary(start_part));
30		}
31
32		// Parse end bound - check for inclusive marker "="
33		if let Some(end_str) = end_part.strip_prefix('=') {
34			if !end_str.is_empty() {
35				bound.1 = Bound::Included(decode_binary(end_str));
36			}
37		} else if !end_part.is_empty() {
38			bound.1 = Bound::Excluded(decode_binary(end_part));
39		}
40
41		Ok(bound)
42	} else {
43		Err(format!("invalid range {s}").into())
44	}
45}