Skip to main content

duckworth_lewis/
lib.rs

1//! This is a rust lib that allows for the calculation of target scores for the
2//! team batting second in a cricket match that has been affected by weather
3//! using the Duckworth Lewis Standard Edition method. Currently the Professional
4//! Edition and Duckworth-Lewis-Stern methodologies aren't published (anywhere
5//! that I'm aware of) so I can't implement them here. Note that international
6//! cricket uses the Duckworth-Lewis-Stern method so the results from this lib
7//! won't match what you see on TV.
8//!
9//! # Features
10//! cli: Produces a binary that provides a command line interface for using the calculator
11//!
12//! ser: Allows the various objects in this crate to be de/serializable using Serde. Included if cli feature used
13
14use std::num::ParseIntError;
15
16use thiserror::Error;
17
18pub use game::{CricketMatch, Grade, Innings};
19pub use overs::Overs;
20
21mod game;
22mod overs;
23mod table;
24
25#[derive(Error, Debug)]
26pub enum DuckworthLewisError {
27    #[error("overs must be in the format <overs>.<balls> got {0}")]
28    InvalidOverFormat(String),
29    #[error("balls must be less than 6, got {0}")]
30    TooManyBalls(u16),
31    #[error("{0}")]
32    OversNotNumeric(String),
33}
34
35impl From<ParseIntError> for DuckworthLewisError {
36    fn from(value: ParseIntError) -> Self {
37        DuckworthLewisError::OversNotNumeric(value.to_string())
38    }
39}