Skip to main content

icydb_core/db/index/key/
id.rs

1use crate::db::identity::{EntityNameError, IndexName, IndexNameError};
2use derive_more::Display;
3use thiserror::Error as ThisError;
4
5///
6/// IndexId
7///
8/// Logical identifier for an index.
9/// Combines entity identity and indexed field set into a stable, ordered name.
10/// Used as the prefix component of all index keys.
11///
12
13#[derive(Clone, Copy, Debug, Display, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct IndexId(pub IndexName);
15
16impl IndexId {
17    /// Maximum sentinel value for stable-memory bounds.
18    /// Used for upper-bound scans and fuzz validation.
19    #[must_use]
20    pub const fn max_storable() -> Self {
21        Self(IndexName::max_storable())
22    }
23}
24
25///
26/// IndexIdError
27/// Errors returned when constructing an [`IndexId`].
28/// This surfaces identity validation failures.
29///
30
31#[derive(Debug, ThisError)]
32pub enum IndexIdError {
33    #[error("entity name invalid: {0}")]
34    EntityName(#[from] EntityNameError),
35
36    #[error("index name invalid: {0}")]
37    IndexName(#[from] IndexNameError),
38}