Skip to main content

reallyme_foundationdb_kit/keys/
prefix.rs

1// SPDX-FileCopyrightText: 2026 ReallyMe LLC
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Typed key prefixes.
5
6use crate::keys::{error::KeyLabelError, validation::validate_static_key_label};
7
8/// A stable key prefix owned by a namespace.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct KeyPrefix {
11    value: &'static str,
12}
13
14impl KeyPrefix {
15    /// Creates a prefix from a compile-time allowlisted value.
16    pub fn from_static(value: &'static str) -> Result<Self, KeyLabelError> {
17        validate_static_key_label(value)?;
18        Ok(Self { value })
19    }
20
21    /// Returns the textual prefix label.
22    pub const fn as_str(self) -> &'static str {
23        self.value
24    }
25}