Skip to main content

reifydb_core/util/encoding/format/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 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 raw;
13
14pub trait Formatter {
15	fn key(key: &[u8]) -> String;
16
17	fn value(key: &[u8], value: &[u8]) -> String;
18
19	fn key_value(key: &[u8], row: impl AsRef<[u8]>) -> String {
20		Self::key_maybe_value(key, Some(row))
21	}
22
23	fn key_maybe_value(key: &[u8], value: Option<impl AsRef<[u8]>>) -> String {
24		let fmtkey = Self::key(key);
25		let fmtvalue = value.map_or("None".to_string(), |v| Self::value(key, v.as_ref()));
26		format!("{fmtkey} => {fmtvalue}")
27	}
28}