Skip to content

Commit

Permalink
docs: add README and .toml properties
Browse files Browse the repository at this point in the history
  • Loading branch information
edugzlez committed Jun 21, 2024
1 parent f1a21da commit 0e670cc
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name = "electosim"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
authors = ["Eduardo González Vaquero <edugonzalezvaq@gmail.com>"]
description = "Library to compute electoral methods (as D'Hondt) and simulate elections"
license = "MIT"
repository = "https://github.com/edugzlez/electosim-rs"

[dependencies]
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ElectoSIM ~ Rust

[![crates.io](https://img.shields.io/crates/v/electosim.svg)](https://crates.io/crates/electosim) [![docs.rs](https://docs.rs/electosim/badge.svg)](https://docs.rs/electosim) [![codecov](https://codecov.io/gh/edugzlez/electosim-rs/graph/badge.svg?token=PZ76N09B8B)](https://codecov.io/gh/edugzlez/electosim-rs)

ElectoSIM is a Rust library for simulating elections using different voting systems.

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
electosim = "0.1.0"
```

or add it directly from crates.io:

```sh
cargo add electosim
```

## Usage

### With SimpleElection

```rust
use electosim::methods::Method;
use electosim::models::Candidacy;

use electosim::SimpleElection;

fn main() {
let mut election = SimpleElection {
results: vec![
Candidacy::new(2010, 9),
Candidacy::new(1018, 4),
Candidacy::new(86, 0),
Candidacy::new(77, 0),
],
seats: 13,
method: Method::HAGENBASCHBISCHOFF,
};

election.compute().expect("Can not compute method");
election.results.iter().for_each(|c| println!("{:?}", c));
}
```

### Directly with the compute_ method

```rust
use electosim::methods::divisor::compute_dhondt;
use electosim::models::Candidacy;

fn main() {
let mut candidacies = vec![
Candidacy::new(2010, 0),
Candidacy::new(1018, 0),
Candidacy::new(86, 0),
Candidacy::new(77, 0),
];
compute_dhondt(&mut candidacies, 13).unwrap();
candidacies.iter().for_each(|c| println!("{:?}", c));
}
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 comments on commit 0e670cc

Please sign in to comment.