1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! A library for the representation and manipulation of betting odds.
//! Includes support for the following types of odds:
//! - [`Fractional`](`odd::Fractional`)
//! - [`Decimal`](`odd::Decimal`)
//! - [`Moneyline`](`odd::Moneyline`)
//!
//! # Basic usage
//! ## Create
//! ```rust
//! use wager::odd::{Decimal, Fractional, Moneyline};
//!
//! // Fractional odds
//! let fractional = Fractional::new(1, 2).unwrap();
//!
//! // Decimal odds
//! let decimal = Decimal::new(1.5).unwrap();
//!
//! // Moneyline odds
//! let moneyline = Moneyline::new(-200).unwrap();
//! ```
//! ## Parse
//!
//! ```rust
//! // Parse odds directly if you know the format ahead of time:
//! use wager::odd::{Decimal, Fractional, Moneyline, Odd, AnyOdd};
//!
//! let fractional = "1/2".parse::<Fractional>().unwrap();
//! let decimal = "1.5".parse::<Decimal>().unwrap();
//! let moneyline = "-200".parse::<Moneyline>().unwrap();
//!
//! // Parse odds generically:
//! match "1/2".parse::<AnyOdd>().unwrap() {
//! AnyOdd::Fractional(fractional) => {} // Do something with fractional odd
//! AnyOdd::Decimal(decimal) => {} // Do something with decimal odd
//! AnyOdd::Moneyline(moneyline) => {} // Do something with moneyline odd
//! }
//! ```
//!
//! ## Convert
//!
//! ```rust
//! use wager::odd::{Decimal, Fractional, Moneyline};
//!
//! let fractional = Fractional::new(1, 2).unwrap();
//! let decimal = Decimal::try_from(fractional).unwrap();
//! let moneyline = Moneyline::try_from(decimal).unwrap();
//! ```
//! <div class="warning">
//! It's very important to note that converting between odds is not always exact.
//! For example, converting a decimal odd to a fractional odd requires the
//! approximation of a real number from a rational number.
//! </div>
//!
//! ## Calculate payout
//!
//! ```rust
//! use wager::odd::{Decimal, Moneyline, Odd};
//!
//! let decimal = Decimal::new(1.5).unwrap();
//! let payout = decimal.payout(100.0);
//! assert_eq!(payout, 150.0);
//!
//! let moneyline = Moneyline::new(-200).unwrap();
//! let payout = moneyline.payout(100.0);
//! assert_eq!(payout, 150.0);
//! ```
//!
//! ## Compare
//!
//! ```rust
//! use wager::odd::{AnyOdd, Decimal, Moneyline};
//!
//! // With same type
//! let a = Decimal::new(1.5).unwrap();
//! let b = Decimal::new(1.6).unwrap();
//! assert!(a < b);
//!
//! // With different types
//! // Need to wrap in an AnyOdd first
//! let a = AnyOdd::Decimal(Decimal::new(1.4).unwrap());
//! let b = AnyOdd::Moneyline(Moneyline::new(-200).unwrap());
//! assert!(a < b);
//! ```