pub struct NameBook { /* private fields */ }Expand description
A DID → name map, populated by the caller from data it already holds.
Insertion is idempotent and order-independent: a lower-ranked source never displaces a higher-ranked one, so a command can fill the book from several responses in whatever order they arrive without the result depending on that order.
Implementations§
Source§impl NameBook
impl NameBook
pub fn new() -> Self
Sourcepub fn insert(&mut self, did: impl Into<String>, name: DisplayName)
pub fn insert(&mut self, did: impl Into<String>, name: DisplayName)
Record a name for did, keeping whichever source ranks higher.
Empty and whitespace-only names are dropped rather than stored: an
unset label deserialises as Some("") often enough that storing it
would put a blank string where the DID should be.
Sourcepub fn insert_opt(
&mut self,
did: impl Into<String>,
name: Option<&str>,
source: NameSource,
)
pub fn insert_opt( &mut self, did: impl Into<String>, name: Option<&str>, source: NameSource, )
Convenience for the common case: an Option<String> label straight
off a response struct.
pub fn get(&self, did: &str) -> Option<&DisplayName>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Sourcepub fn names_any<'a>(&self, dids: impl IntoIterator<Item = &'a str>) -> bool
pub fn names_any<'a>(&self, dids: impl IntoIterator<Item = &'a str>) -> bool
Whether any DID in dids has a name.
Table renderers call this to decide whether to emit a NAME column at all — on a VTA where nothing has been labelled, a column of dashes is worse than no column.
Sourcepub fn name_of(&self, did: &str) -> Option<String>
pub fn name_of(&self, did: &str) -> Option<String>
The name for did as a bare string, tagged when unverified.
Returns None when the DID has no name, so callers can decide between
a placeholder and the shortened DID.
Sourcepub fn render_inline(&self, did: &str) -> String
pub fn render_inline(&self, did: &str) -> String
One-line rendering for prose and confirmations:
mediator-prod (did:webvh:QmXk…9f2:example.com).
Falls back to the shortened DID alone when there is no name. The DID is always present — a name the operator cannot cross-check against an identifier is a name they cannot audit.