|
|
|
@ -50,13 +50,13 @@ macro_rules! wasm_error { |
|
|
|
|
// Init
|
|
|
|
|
|
|
|
|
|
/// Wrapper for [Fixed::set_dps]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
pub fn fixed_set_dps(dps: usize) { |
|
|
|
|
Fixed::set_dps(dps); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [GuardedFixed::set_dps]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
pub fn gfixed_set_dps(dps: usize) { |
|
|
|
|
GuardedFixed::set_dps(dps); |
|
|
|
|
} |
|
|
|
@ -68,7 +68,7 @@ macro_rules! impl_type { |
|
|
|
|
// Counting
|
|
|
|
|
|
|
|
|
|
/// Wrapper for [blt::parse_iterator]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<election_from_blt_$type>](text: String) -> [<Election$type>] { |
|
|
|
|
// Install panic! hook
|
|
|
|
@ -82,21 +82,21 @@ macro_rules! impl_type { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Call [Constraints::from_con] and set [Election::constraints]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<election_load_constraints_$type>](election: &mut [<Election$type>], text: String) { |
|
|
|
|
election.0.constraints = Some(Constraints::from_con(text.lines().map(|s| s.to_string()).into_iter())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [stv::preprocess_election]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<preprocess_election_$type>](election: &mut [<Election$type>], opts: &STVOptions) { |
|
|
|
|
stv::preprocess_election(&mut election.0, &opts.0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [stv::count_init]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<count_init_$type>](state: &mut [<CountState$type>], opts: &STVOptions) { |
|
|
|
|
match stv::count_init(&mut state.0, opts.as_static()) { |
|
|
|
@ -106,7 +106,7 @@ macro_rules! impl_type { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [stv::count_one_stage]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<count_one_stage_$type>](state: &mut [<CountState$type>], opts: &STVOptions) -> bool { |
|
|
|
|
match stv::count_one_stage::<[<$type>]>(&mut state.0, &opts.0) { |
|
|
|
@ -118,42 +118,42 @@ macro_rules! impl_type { |
|
|
|
|
// Reporting
|
|
|
|
|
|
|
|
|
|
/// Wrapper for [init_results_table]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<init_results_table_$type>](election: &[<Election$type>], opts: &STVOptions, report_style: &str) -> String { |
|
|
|
|
return init_results_table(&election.0, &opts.0, report_style); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [describe_count]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<describe_count_$type>](filename: String, election: &[<Election$type>], opts: &STVOptions) -> String { |
|
|
|
|
return describe_count(filename, &election.0, &opts.0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [update_results_table]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<update_results_table_$type>](stage_num: usize, state: &[<CountState$type>], opts: &STVOptions, report_style: &str) -> Array { |
|
|
|
|
return update_results_table(stage_num, &state.0, &opts.0, report_style); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [update_stage_comments]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<update_stage_comments_$type>](state: &[<CountState$type>], stage_num: usize) -> String { |
|
|
|
|
return update_stage_comments(&state.0, stage_num); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [finalise_results_table]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<finalise_results_table_$type>](state: &[<CountState$type>], report_style: &str) -> Array { |
|
|
|
|
return finalise_results_table(&state.0, report_style); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Wrapper for [final_result_summary]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
pub fn [<final_result_summary_$type>](state: &[<CountState$type>], opts: &STVOptions) -> String { |
|
|
|
|
return final_result_summary(&state.0, &opts.0); |
|
|
|
@ -165,9 +165,9 @@ macro_rules! impl_type { |
|
|
|
|
///
|
|
|
|
|
/// This is required as `&'static` cannot be specified in wasm-bindgen: see [issue 1187](https://github.com/rustwasm/wasm-bindgen/issues/1187).
|
|
|
|
|
///
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
pub struct [<CountState$type>](CountState<'static, $type>); |
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
impl [<CountState$type>] { |
|
|
|
|
/// Create a new [CountState] wrapper
|
|
|
|
|
pub fn new(election: &[<Election$type>]) -> Self { |
|
|
|
@ -187,9 +187,9 @@ macro_rules! impl_type { |
|
|
|
|
///
|
|
|
|
|
/// This is required as `&'static` cannot be specified in wasm-bindgen: see [issue 1187](https://github.com/rustwasm/wasm-bindgen/issues/1187).
|
|
|
|
|
///
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
pub struct [<Election$type>](Election<$type>); |
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
impl [<Election$type>] { |
|
|
|
|
/// Return [Election::seats]
|
|
|
|
|
pub fn seats(&self) -> usize { self.0.seats } |
|
|
|
@ -215,10 +215,10 @@ impl_type!(NativeFloat64); |
|
|
|
|
impl_type!(Rational); |
|
|
|
|
|
|
|
|
|
/// Wrapper for [stv::STVOptions]
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
pub struct STVOptions(stv::STVOptions); |
|
|
|
|
|
|
|
|
|
#[wasm_bindgen] |
|
|
|
|
#[cfg_attr(feature = "wasm", wasm_bindgen)] |
|
|
|
|
impl STVOptions { |
|
|
|
|
/// Wrapper for [stv::STVOptions::new]
|
|
|
|
|
pub fn new( |
|
|
|
|