pub struct PeerCache { /* private fields */ }Expand description
In-memory cache PeerKey → PeerCapabilities.
One instance per participant; its lifetime matches the
participant itself. Thread safety is provided by the caller via
Arc<Mutex<PeerCache>> or Arc<RwLock<PeerCache>> — the cache
itself is intentionally not thread-safe, because per tick
usually only one writer/reader task touches it.
Implementations§
Source§impl PeerCache
impl PeerCache
Sourcepub fn insert(&mut self, key: PeerKey, caps: PeerCapabilities)
pub fn insert(&mut self, key: PeerKey, caps: PeerCapabilities)
Full upsert. Overwrites an existing entry
with the new capabilities. For partial updates
use Self::update_partial.
Sourcepub fn get(&self, key: &PeerKey) -> Option<&PeerCapabilities>
pub fn get(&self, key: &PeerKey) -> Option<&PeerCapabilities>
Reads the capabilities of a peer.
Sourcepub fn update_partial(&mut self, key: PeerKey, update: &PeerCapabilities)
pub fn update_partial(&mut self, key: PeerKey, update: &PeerCapabilities)
Merges new information into the existing entry. If the peer is new → it is inserted.
For the semantics see PeerCapabilities::merge_update.
Sourcepub fn forget(&mut self, key: &PeerKey) -> Option<PeerCapabilities>
pub fn forget(&mut self, key: &PeerKey) -> Option<PeerCapabilities>
Removes a peer from the cache. Returns the old caps if present — handy for logging at session end.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&PeerKey, &PeerCapabilities)>
pub fn iter(&self) -> impl Iterator<Item = (&PeerKey, &PeerCapabilities)>
Iterator over all (PeerKey, PeerCapabilities) pairs.