Remove CountStateOrRef
This commit is contained in:
parent
34545ad179
commit
9b73a4adf4
@ -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
|
/// Result of a stage of counting
|
||||||
pub struct StageResult<'a, N: Number> {
|
pub struct StageResult<'a, N: Number> {
|
||||||
/// See [CountState::kind]
|
/// See [CountState::kind]
|
||||||
@ -291,8 +265,8 @@ pub struct StageResult<'a, N: Number> {
|
|||||||
pub title: &'a String,
|
pub title: &'a String,
|
||||||
/// Detailed logs of this stage, rendered from [CountState::logger]
|
/// Detailed logs of this stage, rendered from [CountState::logger]
|
||||||
pub logs: Vec<String>,
|
pub logs: Vec<String>,
|
||||||
/// Reference to the [CountState] or cloned [CountState] of this stage
|
/// Reference to the [CountState] of this stage
|
||||||
pub state: CountStateOrRef<'a, N>,
|
pub state: &'a CountState<'a, N>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Current state of a [Candidate] during an election count
|
/// Current state of a [Candidate] during an election count
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use opentally::constraints::Constraints;
|
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::numbers::{Fixed, GuardedFixed, NativeFloat64, Number, Rational};
|
||||||
use opentally::stv;
|
use opentally::stv;
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ fn print_stage<N: Number>(stage_num: usize, result: &StageResult<N>, cmd_opts: &
|
|||||||
};
|
};
|
||||||
println!("{}", result.logs.join(" "));
|
println!("{}", result.logs.join(" "));
|
||||||
|
|
||||||
let state = result.state.as_ref();
|
let state = result.state;
|
||||||
|
|
||||||
// Print candidates
|
// Print candidates
|
||||||
if cmd_opts.sort_votes {
|
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,
|
kind: state.kind,
|
||||||
title: &state.title,
|
title: &state.title,
|
||||||
logs: state.logger.render(),
|
logs: state.logger.render(),
|
||||||
state: CountStateOrRef::from(&state),
|
state: &state,
|
||||||
};
|
};
|
||||||
print_stage(stage_num, &result, &cmd_opts);
|
print_stage(stage_num, &result, &cmd_opts);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user