pub struct AttributableMap<T: Attributable> { /* private fields */ }Expand description
A map of Attributable items keyed by their signer index.
The key for each item is automatically inferred from Attributable::signer(). Each signer can insert at most one item.
Implementations§
Source§impl<T: Attributable> AttributableMap<T>
impl<T: Attributable> AttributableMap<T>
Sourcepub fn new(participants: usize) -> Self
pub fn new(participants: usize) -> Self
Creates a new AttributableMap with the given number of participants.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all existing items from the AttributableMap.
Sourcepub fn insert(&mut self, item: T) -> bool
pub fn insert(&mut self, item: T) -> bool
Inserts an item into the map, using Attributable::signer() as the key, if it has not been added yet.
Returns true if the item was inserted, false if an item from this
signer already exists or if the signer index is out of bounds.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of items in the AttributableMap.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true if the AttributableMap is empty.
Sourcepub fn get(&self, signer: u32) -> Option<&T>
pub fn get(&self, signer: u32) -> Option<&T>
Returns a reference to the item associated with the given signer, if present.
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Returns an iterator over items in the map, ordered by signer index (Attributable::signer()).
Auto Trait Implementations§
impl<T> Freeze for AttributableMap<T>
impl<T> RefUnwindSafe for AttributableMap<T>where
T: RefUnwindSafe,
impl<T> Send for AttributableMap<T>where
T: Send,
impl<T> Sync for AttributableMap<T>where
T: Sync,
impl<T> Unpin for AttributableMap<T>where
T: Unpin,
impl<T> UnwindSafe for AttributableMap<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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