Skip to main content

reifydb_core/util/encoding/format/
raw.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2026 ReifyDB
3
4use std::ascii;
5
6use crate::util::encoding::format::Formatter;
7
8pub struct Raw;
9
10impl Raw {
11	pub fn bytes(bytes: &[u8]) -> String {
12		let escaped = bytes.iter().copied().flat_map(ascii::escape_default).collect::<Vec<_>>();
13		format!("\"{}\"", String::from_utf8_lossy(&escaped))
14	}
15}
16
17impl Formatter for Raw {
18	fn key(key: &[u8]) -> String {
19		Self::bytes(key)
20	}
21
22	fn value(_key: &[u8], value: &[u8]) -> String {
23		Self::bytes(value)
24	}
25}