Crates.io | scoreboard_world_cup |
lib.rs | scoreboard_world_cup |
version | 0.1.1 |
source | src |
created_at | 2023-11-08 12:06:36.486273 |
updated_at | 2023-11-08 12:33:17.444437 |
description | Simple score board for following the results of the currently played games in a World Cup |
homepage | https://crates.io/crates/scoreboard_world_cup |
repository | https://github.com/Daydreamest/scoreboard |
max_upload_size | |
id | 1028997 |
size | 2,241,292 |
Develop a new live World Cup scorebard library that shows all the ongoing matches and their scores
Requirement | Status | Comments |
---|---|---|
1. Library | ![]() |
Devloped as an independant Rust library crate |
2. Storage | ![]() |
Using standard Vec vector collection. See "Possible additional features -> Optimization" below for more comments on this |
3. TDD | ![]() |
TDD followed to a degree. Most functions are so small it was possible to write the final correct version for the first test and then add the other corner cases |
4. API | ![]() |
Public ScoreBoard struct and its methods |
4.1. Start | ![]() |
ScoreBoard.start_game(home_team_name, away_team_name) |
4.2. Update | ![]() |
ScoreBoard.update_score(home_team_name, home_score, away_team_name, away_score) |
4.3. Finish | ![]() |
ScoreBoard.finish_game(home_team_name, away_team_name) |
4.4. Summary | ![]() |
ScoreBoard.get_summary() |
Features | Status | Comments |
---|---|---|
Team uniqueness | ![]() |
start_game(team1, team2) rejects the request if any of the teams is already playing a match |
Thread safety | ![]() |
Rust compiler provides thread safety, unless serious hacks get involved. There is no unsafe code in this repository |
The project is documented with code annotations
Run this command to generate documentation and open it:
cargo doc --open
The generated documentation is available on GitHub Pages under daydreamest.github.io or on crates.io
Move to the "scoreboard" directory and run:
> cargo build --release
On the first execution Cargo will download dependencies (ex. the logging crate). After that, the library will be compiled to a binary:
scoreboard/target/release/libscoreboard.rlib
Copy the scoreboard.rs
file to your project and include the module anywhere you need it with:
use scoreboard::*;
Copy compiled libscoreboard.rlib
file to your project and add a flag to your compilation options:
rustc main.rs --extern scoreboard=libscoreboard.rlib
Add the following line in Cargo.toml
file under [dependencies]
:
scoreboard_world_cup = "0.1.1"
To run tests move to the "scoreboard" directory and run:
> cargo test
update_score()
is very unwieldy and allows to change the score arbitrarily. In footbal the score changes come in quanta (commonly known as "goals"), so there should be a method add_goal(team_name)
that adds 1 to the score of the mentioned teamVec
is used as a data container. There are others collections available, but even the Rust guide suggests sticking to the good, reliable vector. Alternatives could be considered to improve efficiency, but they would need profiling and real world usage of the libraryget_summary()
method would have to be mutable and change the state of the score board, which is a bad designget_summary()
could make a copy of the data an sort it locally before returning, but this adds unnecessary memory usageget_summary()
is expected to be called much more often than all the other API functions combined, so it has to be quick and simple. Adding sorting to it can have serious time impact for a large number of concurrent matchessort()
does extremely well with collections that are partly sorted or have stretches of sorted elements (source). As such, it should have little impact on the functions that use it now, as their changes apply to single matches and leave the rest of the collection sortedVec
and push()
could be considered that might allow to skip sorting in some cases. A newly created match has the lowes possible total score and the freshest timestamp, so sorting on start_game()
could be probably omitted, but this requires more analysis