pub struct MemoryStore<T = ()> { /* private fields */ }
Expand description
A in-memory store that uses LRU cache for bounded storage of addresses and a frequency-based ordering of addresses.
Implementations§
Source§impl<T> MemoryStore<T>
impl<T> MemoryStore<T>
Sourcepub fn new(config: Config) -> Self
pub fn new(config: Config) -> Self
Create a new MemoryStore
with the given config.
Sourcepub fn add_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
pub fn add_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
Add an address for a peer.
The added address will NOT be removed from the store on dial failure. If the added address
is supposed to be cleared from the store on dial failure, add it by emitting
[FromSwarm::NewExternalAddrOfPeer
] to the swarm, e.g. via
Swarm::add_peer_address
.
Returns true
if the address is new.
Sourcepub fn remove_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
pub fn remove_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
Remove an address record.
Returns true
when the address existed.
Sourcepub fn get_custom_data(&self, peer: &PeerId) -> Option<&T>
pub fn get_custom_data(&self, peer: &PeerId) -> Option<&T>
Get a reference to a peer’s custom data.
Sourcepub fn take_custom_data(&mut self, peer: &PeerId) -> Option<T>
pub fn take_custom_data(&mut self, peer: &PeerId) -> Option<T>
Take ownership of the internal data, leaving None
in its place.
Sourcepub fn insert_custom_data(&mut self, peer: &PeerId, custom_data: T)
pub fn insert_custom_data(&mut self, peer: &PeerId, custom_data: T)
Insert the data, dropping the old data if it exists.
Sourcepub fn get_custom_data_mut(&mut self, peer: &PeerId) -> Option<&mut T>
pub fn get_custom_data_mut(&mut self, peer: &PeerId) -> Option<&mut T>
Get a mutable reference to a peer’s custom data.
Sourcepub fn record_iter(&self) -> impl Iterator<Item = (&PeerId, &PeerRecord<T>)>
pub fn record_iter(&self) -> impl Iterator<Item = (&PeerId, &PeerRecord<T>)>
Iterate over all internal records.
Sourcepub fn record_iter_mut(
&mut self,
) -> impl Iterator<Item = (&PeerId, &mut PeerRecord<T>)>
pub fn record_iter_mut( &mut self, ) -> impl Iterator<Item = (&PeerId, &mut PeerRecord<T>)>
Iterate over all internal records mutably.
Changes to the records will not generate an event.
Trait Implementations§
Source§impl<T: Default> Default for MemoryStore<T>
impl<T: Default> Default for MemoryStore<T>
Source§fn default() -> MemoryStore<T>
fn default() -> MemoryStore<T>
Source§impl<T> Store for MemoryStore<T>
impl<T> Store for MemoryStore<T>
Auto Trait Implementations§
impl<T> Freeze for MemoryStore<T>
impl<T> RefUnwindSafe for MemoryStore<T>where
T: RefUnwindSafe,
impl<T> Send for MemoryStore<T>where
T: Send,
impl<T> Sync for MemoryStore<T>where
T: Sync,
impl<T> Unpin for MemoryStore<T>where
T: Unpin,
impl<T> UnwindSafe for MemoryStore<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more