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 update_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
pub fn update_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
Update an address record and notify swarm when the address is new.
Returns true
when the address is new.
pub fn update_address_silent(
&mut self,
peer: &PeerId,
address: &Multiaddr,
) -> bool
pub fn update_address_silent( &mut self, peer: &PeerId, address: &Multiaddr, ) -> bool
Update an address record without notifying swarm.
Returns true
when 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 is removed.
pub fn get_custom_data(&self, peer: &PeerId) -> Option<&T>
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 and notify the swarm about the update, dropping the old data if it exists.
pub fn insert_custom_data_silent(&mut self, peer: &PeerId, custom_data: T)
pub fn insert_custom_data_silent(&mut self, peer: &PeerId, custom_data: T)
Insert the data without notifying the swarm. Old data will be dropped if it exists.
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.
Will not wake up the task.
Trait Implementations§
§impl<T> Default for MemoryStore<T>where
T: Default,
impl<T> Default for MemoryStore<T>where
T: Default,
§fn default() -> MemoryStore<T>
fn default() -> 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§
§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,
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> ⓘ
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