Struct finality_grandpa::voter_set::VoterSet [−][src]
A (non-empty) set of voters and associated weights.
A VoterSet
identifies all voters that are permitted to vote in a round
of the protocol and their associated weights. A VoterSet
is furthermore
equipped with a total order, given by the ordering of the voter’s IDs.
Implementations
impl<Id: Eq + Ord> VoterSet<Id>
[src]
pub fn new<I>(weights: I) -> Option<Self> where
Id: Ord + Clone,
I: IntoIterator<Item = (Id, u64)>,
[src]
Id: Ord + Clone,
I: IntoIterator<Item = (Id, u64)>,
Create a voter set from a weight distribution produced by the given iterator.
If the distribution contains multiple weights for the same voter ID, they are understood to be partial weights and are accumulated. As a result, the order in which the iterator produces the weights is irrelevant.
Returns None
if the iterator does not yield a valid voter set, which is
the case if it either produced no non-zero weights or, i.e. the voter set
would be empty, or if the total voter weight exceeds u64::MAX
.
pub fn get(&self, id: &Id) -> Option<&VoterInfo>
[src]
Get the voter info for the voter with the given ID, if any.
pub fn len(&self) -> NonZeroUsize
[src]
Get the size of the set.
pub fn contains(&self, id: &Id) -> bool
[src]
Whether the set contains a voter with the given ID.
pub fn nth_mod(&self, n: usize) -> (&Id, &VoterInfo)
[src]
Get the nth voter in the set, modulo the size of the set, as per the associated total order.
pub fn nth(&self, n: usize) -> Option<(&Id, &VoterInfo)>
[src]
Get the nth voter in the set, if any.
Returns None
if n >= len
.
pub fn threshold(&self) -> VoterWeight
[src]
Get the threshold vote weight required for supermajority w.r.t. this set of voters.
pub fn total_weight(&self) -> VoterWeight
[src]
Get the total weight of all voters.
pub fn iter(&self) -> impl Iterator<Item = (&Id, &VoterInfo)>
[src]
Get an iterator over the voters in the set, as given by the associated total order.
Trait Implementations
impl<Id: Clone + Eq + Ord> Clone for VoterSet<Id>
[src]
impl<Id: Debug + Eq + Ord> Debug for VoterSet<Id>
[src]
impl<Id: Eq + Ord> Eq for VoterSet<Id>
[src]
impl<Id: PartialEq + Eq + Ord> PartialEq<VoterSet<Id>> for VoterSet<Id>
[src]
impl<Id: Eq + Ord> StructuralEq for VoterSet<Id>
[src]
impl<Id: Eq + Ord> StructuralPartialEq for VoterSet<Id>
[src]
Auto Trait Implementations
impl<Id> RefUnwindSafe for VoterSet<Id> where
Id: RefUnwindSafe,
Id: RefUnwindSafe,
impl<Id> Send for VoterSet<Id> where
Id: Send,
Id: Send,
impl<Id> Sync for VoterSet<Id> where
Id: Sync,
Id: Sync,
impl<Id> Unpin for VoterSet<Id> where
Id: Unpin,
Id: Unpin,
impl<Id> UnwindSafe for VoterSet<Id> where
Id: RefUnwindSafe + UnwindSafe,
Id: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,