chore(core): add Default impls + FieldId uniqueness test
Code review fixups: - ItemId/FieldId need impl Default delegating to ::new() to silence clippy::new_without_default - FieldId was missing the parallel uniqueness test that ItemId has Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,10 @@ impl ItemId {
|
||||
pub fn as_str(&self) -> &str { &self.0 }
|
||||
}
|
||||
|
||||
impl Default for ItemId {
|
||||
fn default() -> Self { Self::new() }
|
||||
}
|
||||
|
||||
impl FieldId {
|
||||
pub fn new() -> Self {
|
||||
let mut bytes = [0u8; 8];
|
||||
@@ -40,6 +44,10 @@ impl FieldId {
|
||||
pub fn as_str(&self) -> &str { &self.0 }
|
||||
}
|
||||
|
||||
impl Default for FieldId {
|
||||
fn default() -> Self { Self::new() }
|
||||
}
|
||||
|
||||
impl AttachmentId {
|
||||
pub fn from_plaintext(plaintext: &[u8]) -> Self {
|
||||
let digest = Sha256::digest(plaintext);
|
||||
@@ -74,6 +82,14 @@ mod tests {
|
||||
assert!(id.0.chars().all(|c| c.is_ascii_hexdigit()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn field_ids_are_unique() {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for _ in 0..10_000 {
|
||||
assert!(seen.insert(FieldId::new().0));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn attachment_id_is_deterministic() {
|
||||
let plaintext = b"hello world";
|
||||
|
||||
Reference in New Issue
Block a user