cstat/archive/overcomplicated/crates/cstat-schema/src/ids.rs
Zachery Aaron Shores-Chmielewski cced49e3ed Archive overcomplicated workspace, restore legacy cstat at root
The milestone-1 multi-crate representation stack overshot the goal.
Move it to archive/overcomplicated/ to keep for reference, and bring
the original single-package cstat back to /workspace as the active
codebase. Also commit demo_glossary.rs and ignore the build binary
plus .loop/.stash/.

Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
2026-07-12 11:00:45 +04:00

89 lines
2.8 KiB
Rust

//! Cross-level identity types per spec §6.
//!
//! Every per-entity record carries the set of IDs by which it is known.
//! Cross-level joins are explicit on these IDs.
use serde::{Deserialize, Serialize};
/// Project-relative path, posix-normalized (forward slashes).
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct FileId(pub String);
impl FileId {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
/// Crate-qualified module path, e.g. `cstat::diagnostics::scoring`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct ModuleId(pub String);
impl ModuleId {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
/// Identifies a syntactic function item: `(file, fq_path, item_kind, ast_node_hash)`.
///
/// `ast_node_hash` is a structural hash of the item; it survives reformatting
/// but not real edits, and distinguishes overloads / multiple `impl` blocks.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct AstFuncId {
pub file: FileId,
pub fq_path: String,
pub item_kind: String,
pub ast_node_hash: String,
}
/// Mangled symbol name (post-rustc mangling).
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct SymbolId(pub String);
impl SymbolId {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
/// Demangled symbol with type substitutions, joinable to AstFuncId.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct MonoId(pub String);
impl MonoId {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
/// All IDs an entity may be known by (spec §6). Any subset may be present.
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct IdSet {
#[serde(rename = "FileId", skip_serializing_if = "Option::is_none", default)]
pub file: Option<FileId>,
#[serde(rename = "ModuleId", skip_serializing_if = "Option::is_none", default)]
pub module: Option<ModuleId>,
#[serde(rename = "AstFuncId", skip_serializing_if = "Option::is_none", default)]
pub ast_func: Option<AstFuncId>,
#[serde(rename = "SymbolId", skip_serializing_if = "Option::is_none", default)]
pub symbol: Option<SymbolId>,
#[serde(rename = "MonoId", skip_serializing_if = "Option::is_none", default)]
pub mono: Option<MonoId>,
}