Remove CountStateOrRef

This commit is contained in:
RunasSudo 2021-06-29 01:27:10 +10:00
parent 34545ad179
commit 9b73a4adf4
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 5 additions and 31 deletions

View File

@ -257,32 +257,6 @@ impl<'a, N: Number> CountState<'a, N> {
}
}
/// Represents either a reference to a [CountState] or a clone
#[allow(dead_code)]
pub enum CountStateOrRef<'a, N: Number> {
/// Cloned [CountState]
///
/// Currently unused/unimplemented, but may be used in future for rollback-based constraints
State(CountState<'a, N>),
/// Reference to a [CountState]
Ref(&'a CountState<'a, N>),
}
impl<'a, N: Number> CountStateOrRef<'a, N> {
/// Construct a [CountStateOrRef] as a reference to a [CountState]
pub fn from(state: &'a CountState<N>) -> Self {
return Self::Ref(state);
}
/// Return a reference to the underlying [CountState]
pub fn as_ref(&self) -> &CountState<N> {
match self {
CountStateOrRef::State(state) => &state,
CountStateOrRef::Ref(state) => state,
}
}
}
/// Result of a stage of counting
pub struct StageResult<'a, N: Number> {
/// See [CountState::kind]
@ -291,8 +265,8 @@ pub struct StageResult<'a, N: Number> {
pub title: &'a String,
/// Detailed logs of this stage, rendered from [CountState::logger]
pub logs: Vec<String>,
/// Reference to the [CountState] or cloned [CountState] of this stage
pub state: CountStateOrRef<'a, N>,
/// Reference to the [CountState] of this stage
pub state: &'a CountState<'a, N>,
}
/// Current state of a [Candidate] during an election count

View File

@ -16,7 +16,7 @@
*/
use opentally::constraints::Constraints;
use opentally::election::{Candidate, CandidateState, CountCard, CountState, CountStateOrRef, Election, StageResult};
use opentally::election::{Candidate, CandidateState, CountCard, CountState, Election, StageResult};
use opentally::numbers::{Fixed, GuardedFixed, NativeFloat64, Number, Rational};
use opentally::stv;
@ -358,7 +358,7 @@ fn print_stage<N: Number>(stage_num: usize, result: &StageResult<N>, cmd_opts: &
};
println!("{}", result.logs.join(" "));
let state = result.state.as_ref();
let state = result.state;
// Print candidates
if cmd_opts.sort_votes {
@ -398,7 +398,7 @@ fn make_and_print_result<N: Number>(stage_num: usize, state: &CountState<N>, cmd
kind: state.kind,
title: &state.title,
logs: state.logger.render(),
state: CountStateOrRef::from(&state),
state: &state,
};
print_stage(stage_num, &result, &cmd_opts);
}