Struct MemoryStore
pub struct MemoryStore<T = ()> { /* private fields */ }peer-store only.Expand description
A in-memory store that uses LRU cache for bounded storage of addresses and a frequency-based ordering of addresses.
Implementations§
§impl<T> MemoryStore<T>
impl<T> MemoryStore<T>
pub fn new(config: Config) -> MemoryStore<T>
pub fn new(config: Config) -> MemoryStore<T>
Create a new MemoryStore with the given config.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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§
Auto Trait Implementations§
impl<T> Forget for MemoryStore<T>
impl<T> Freeze for MemoryStore<T>
impl<T> Move for MemoryStore<T>
impl<T> RefUnwindSafe for MemoryStore<T>
impl<T> Send for MemoryStore<T>
impl<T> Sync for MemoryStore<T>
impl<T> Unpin for MemoryStore<T>
impl<T> UnsafeUnpin for MemoryStore<T>
impl<T> UnwindSafe for MemoryStore<T>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§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