pub fn add_vote<W>(&mut self, choice: Choice, weight: W) -> Result<(), TallyError>
    where
        W: Into<Weight>,
    {
        let weight = weight.into();

        if !self.options.validate(choice) {
            Err(TallyError::InvalidChoice {
                options: self.options.clone(),
                choice,
            })
        } else if weight.is_zero() {
            // we simply ignore the case where the `weight` is nul
            //
            // this may have been just as good as to not do the check as we would have
            // add `0` to the results. However just so we know this is handled
            // properly we know that adding a weight of `0` is ignored
            Ok(())
        } else {
            let index = choice.as_byte() as usize;

            self.results[index].saturating_add(weight);

            Ok(())
        }
    }
/// add a vote and its weight on the tally
///
/// if the vote's weight is null (`0`), nothing will be changed.
///
/// # Errors
///
/// The function will fail if the `choice` is not a valid `Option`
add a vote and its weight on the tally
if the vote's weight is null (`0`), nothing will be changed.
add a vote and its weight on the tally if the vote ' s weight is null ( ` 0 ` ) nothing will be changed .
pub fn add_vote<W>(&mut self, choice: Choice, weight: W) -> Result<(), TallyError>
    where
        W: Into<Weight>,
    {
        let weight = weight.into();
        if !self.options.validate(choice) {
            Err(TallyError::InvalidChoice {
                options: self.options.clone(),
                choice,
            })
        } else if weight.is_zero() {
            // we simply ignore the case where the `weight` is nul
            //
            // this may have been just as good as to not do the check as we would have
            // add `0` to the results. However just so we know this is handled
            // properly we know that adding a weight of `0` is ignored
            Ok(())
        } else {
            let index = choice.as_byte() as usize;
            self.results[index].saturating_add(weight);
            Ok(())
        }
    }
pub fn add_vote < W > ( & mut self , choice : Choice , weight : W ) -> Result < ( ) , TallyError > where W : Into < Weight > , { let weight = weight . into ( ) ; if ! self . options . validate ( choice ) { Err ( TallyError :: InvalidChoice { options : self . options . clone ( ) , choice , } ) } else if weight . is_zero ( ) { // we simply ignore the case where the `weight` is nul // // this may have been just as good as to not do the check as we would have // add `0` to the results. However just so we know this is handled // properly we know that adding a weight of `0` is ignored Ok ( ( ) ) } else { let index = choice . as_byte ( ) as usize ; self . results [ index ] . saturating_add ( weight ) ; Ok ( ( ) ) } }
add a vote and its weight on the tally
if the vote's weight is null (`0`), nothing will be changed.
add a vote and its weight on the tally if the vote ' s weight is null ( ` 0 ` ) nothing will be changed .
&mut self
choice
Choice
weight
W
&mut self
choice
Choice
weight
W
errors
The function will fail if the `choice` is not a valid `Option`
The function will fail if the ` choice ` is not a valid ` Option `