From 9b73a4adf4d714e16141a99c2ef1373731f6b7ae Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 29 Jun 2021 01:27:10 +1000 Subject: [PATCH] Remove CountStateOrRef --- src/election.rs | 30 ++---------------------------- src/main.rs | 6 +++--- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/election.rs b/src/election.rs index d4e1e70..24bb3f1 100644 --- a/src/election.rs +++ b/src/election.rs @@ -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) -> Self { - return Self::Ref(state); - } - - /// Return a reference to the underlying [CountState] - pub fn as_ref(&self) -> &CountState { - 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, - /// 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 diff --git a/src/main.rs b/src/main.rs index fe7f519..a5ddc6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(stage_num: usize, result: &StageResult, 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(stage_num: usize, state: &CountState, cmd kind: state.kind, title: &state.title, logs: state.logger.render(), - state: CountStateOrRef::from(&state), + state: &state, }; print_stage(stage_num, &result, &cmd_opts); }