Struct tp_npos_elections::Assignment[][src]

pub struct Assignment<AccountId, P: PerThing> {
    pub who: AccountId,
    pub distribution: Vec<(AccountId, P)>,
}

A voter’s stake assignment among a set of targets, represented as ratios.

Fields

who: AccountId

Voter’s identifier.

distribution: Vec<(AccountId, P)>

The distribution of the voter’s stake.

Implementations

impl<AccountId: IdentifierT, P: PerThing128> Assignment<AccountId, P>[src]

pub fn into_staked(self, stake: ExtendedBalance) -> StakedAssignment<AccountId>[src]

Convert from a ratio assignment into one with absolute values aka. StakedAssignment.

It needs stake which is the total budget of the voter.

Note that this might create un-normalized assignments, due to accuracy loss of P. Call site might compensate by calling try_normalize() on the returned StakedAssignment as a post-precessing.

If an edge ratio is Bounded::min_value(), it is dropped. This edge can never mean anything useful.

pub fn try_normalize(&mut self) -> Result<(), &'static str>[src]

Try and normalize this assignment.

If Ok(()) is returned, then the assignment MUST have been successfully normalized to 100%.

Errors

This will return only if the internal normalize fails. This can happen if sum of self.distribution.map(|p| p.deconstruct()) fails to fit inside UpperOf<P>. A user of this crate may statically assert that this can never happen and safely expect this to return Ok.

Trait Implementations

impl<AccountId: Clone, P: Clone + PerThing> Clone for Assignment<AccountId, P>[src]

impl<AccountId, P: PerThing> Debug for Assignment<AccountId, P> where
    AccountId: Debug,
    P: Debug
[src]

impl<AccountId, P: PerThing> Decode for Assignment<AccountId, P> where
    AccountId: Decode,
    AccountId: Decode,
    Vec<(AccountId, P)>: Decode,
    Vec<(AccountId, P)>: Decode
[src]

impl<AccountId: Default, P: Default + PerThing> Default for Assignment<AccountId, P>[src]

impl<AccountId, P: PerThing> Encode for Assignment<AccountId, P> where
    AccountId: Encode,
    AccountId: Encode,
    Vec<(AccountId, P)>: Encode,
    Vec<(AccountId, P)>: Encode
[src]

impl<AccountId, P: PerThing> EncodeLike<Assignment<AccountId, P>> for Assignment<AccountId, P> where
    AccountId: Encode,
    AccountId: Encode,
    Vec<(AccountId, P)>: Encode,
    Vec<(AccountId, P)>: Encode
[src]

impl<AccountId: Eq, P: Eq + PerThing> Eq for Assignment<AccountId, P>[src]

impl<AccountId: PartialEq, P: PartialEq + PerThing> PartialEq<Assignment<AccountId, P>> for Assignment<AccountId, P>[src]

impl<AccountId, P: PerThing> StructuralEq for Assignment<AccountId, P>[src]

impl<AccountId, P: PerThing> StructuralPartialEq for Assignment<AccountId, P>[src]

Auto Trait Implementations

impl<AccountId, P> RefUnwindSafe for Assignment<AccountId, P> where
    AccountId: RefUnwindSafe,
    P: RefUnwindSafe

impl<AccountId, P> Send for Assignment<AccountId, P> where
    AccountId: Send,
    P: Send

impl<AccountId, P> Sync for Assignment<AccountId, P> where
    AccountId: Sync,
    P: Sync

impl<AccountId, P> Unpin for Assignment<AccountId, P> where
    AccountId: Unpin,
    P: Unpin

impl<AccountId, P> UnwindSafe for Assignment<AccountId, P> where
    AccountId: UnwindSafe,
    P: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<S> Codec for S where
    S: Decode + Encode
[src]

impl<T> DecodeAll for T where
    T: Decode
[src]

impl<T> DecodeLimit for T where
    T: Decode
[src]

impl<T> Downcast for T where
    T: Any

impl<T> DowncastSync for T where
    T: Any + Send + Sync

impl<T> DynClone for T where
    T: Clone
[src]

impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ T> for T where
    T: Encode
[src]

impl<'_, T> EncodeLike<&'_ mut T> for T where
    T: Encode
[src]

impl<T> EncodeLike<Arc<T>> for T where
    T: Encode
[src]

impl<T> EncodeLike<Box<T, Global>> for T where
    T: Encode
[src]

impl<'a, T> EncodeLike<Cow<'a, T>> for T where
    T: ToOwned + Encode
[src]

impl<T> EncodeLike<Rc<T>> for T where
    T: Encode
[src]

impl<T> From<T> for T[src]

impl<S> FullCodec for S where
    S: Decode + FullEncode
[src]

impl<S> FullEncode for S where
    S: Encode + EncodeLike<S>, 
[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Outer> IsWrappedBy<Outer> for T where
    T: From<Outer>,
    Outer: AsRef<T> + AsMut<T> + From<T>, 
[src]

pub fn from_ref(outer: &Outer) -> &T[src]

Get a reference to the inner from the outer.

pub fn from_mut(outer: &mut Outer) -> &mut T[src]

Get a mutable reference to the inner from the outer.

impl<T> KeyedVec for T where
    T: Codec
[src]

impl<T> MaybeDebug for T where
    T: Debug

impl<T> MaybeRefUnwindSafe for T where
    T: RefUnwindSafe

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SaturatedConversion for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<S, T> UncheckedInto<T> for S where
    T: UncheckedFrom<S>, 
[src]

impl<T, S> UniqueSaturatedInto<T> for S where
    T: Bounded,
    S: TryInto<T>, 
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,