electosim/macros.rs
1/// Creates a new [SimpleElection] struct.
2/// # Arguments
3/// * `results` - A vector of [Candidacy] structs.
4/// * `seats` - The number of seats available in the election.
5/// * `method` - The method to be used for the election.
6/// * `cutoff` - The electoral cutoff.
7/// # Example
8/// ```
9/// use electosim::*;
10///
11/// let election = election!(
12/// vec![
13/// candidacy!(2010, 9),
14/// candidacy!(1018, 4),
15/// candidacy!(86, 0),
16/// candidacy!(77, 0),
17/// ],
18/// 13,
19/// Method::HAGENBASCHBISCHOFF,
20/// 0.1
21/// );
22/// ```
23#[macro_export]
24macro_rules! election {
25 ($results:expr) => {
26 $crate::SimpleElection {
27 results: $results,
28 seats: 0,
29 method: electosim::Method::DHONDT,
30 cutoff: 0.0,
31 }
32 };
33 ($results:expr, $seats:expr) => {
34 $crate::SimpleElection {
35 results: $results,
36 seats: $seats,
37 method: electosim::Method::DHONDT,
38 cutoff: 0.0,
39 }
40 };
41 ($results:expr, $seats:expr, $method:expr) => {
42 $crate::SimpleElection {
43 results: $results,
44 seats: $seats,
45 method: $method,
46 cutoff: 0.0,
47 }
48 };
49 ($results:expr, $seats:expr, $method:expr, $coff:expr) => {
50 $crate::SimpleElection {
51 results: $results,
52 seats: $seats,
53 method: $method,
54 cutoff: $coff,
55 }
56 };
57}
58
59#[macro_export]
60macro_rules! candidacy {
61 ($votes:expr) => {
62 $crate::Candidacy::new($votes, 0)
63 };
64 ($votes:expr, $seats:expr) => {
65 $crate::Candidacy::new($votes, $seats)
66 };
67}