core: implement display for typed ids

This commit is contained in:
a.tolmachev
2026-04-12 11:26:45 +03:00
parent 1cb4cbc960
commit 99a5d44fea
2 changed files with 25 additions and 5 deletions
+5 -5
View File
@@ -2,18 +2,18 @@
## Current ## Current
### `feat/id-display-support` ### `feat/secret-crypto-hkdf`
Status: in_progress Status: in_progress
DoD: DoD:
- `define_id!` implements `Display` - master key derivation uses HKDF-SHA256 instead of raw SHA256
- formatting with typed ids no longer requires pervasive `.as_str()` - secret encryption/decryption compatibility is explicit and tested
- the workspace builds cleanly after the macro change - admin-api and runtime continue to handle secret crypto through the shared path
## Next ## Next
- `feat/secret-crypto-hkdf` - `feat/postgres-pool-config`
## Backlog ## Backlog
+20
View File
@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt;
macro_rules! define_id { macro_rules! define_id {
($name:ident) => { ($name:ident) => {
@@ -32,6 +33,12 @@ macro_rules! define_id {
self.as_str() self.as_str()
} }
} }
impl fmt::Display for $name {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
}; };
} }
@@ -50,3 +57,16 @@ define_id!(InvocationLogId);
define_id!(SecretId); define_id!(SecretId);
define_id!(StreamSessionId); define_id!(StreamSessionId);
define_id!(AsyncJobId); define_id!(AsyncJobId);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ids_implement_display() {
let workspace_id = WorkspaceId::new("ws_default");
assert_eq!(workspace_id.to_string(), "ws_default");
assert_eq!(format!("{workspace_id}"), "ws_default");
}
}