Skip to main content

weighted_list/
root.rs

1use std::*;
2
3use num_traits as nums;
4
5
6/// Any numerical type, such as `u32`, `usize`, `f64`. The type `W` of item weights in a [`WeightedList<V,W>`](crate::WeightedList) must implement this trait.
7pub trait Weight:
8      Copy
9    + nums::NumAssign
10    + nums::NumCast
11    + PartialOrd
12    + iter::Sum
13    + fmt::Debug
14{}
15
16/// Auto implementation for all types that fulfil the trait’s requirements.
17impl<Type> Weight for Type where Type:
18      Copy
19    + nums::NumAssign
20    + nums::NumCast
21    + PartialOrd
22    + iter::Sum
23    + fmt::Debug
24{}
25
26
27/// An error returned when failing to cast one numeric type to another, which may be required for certain [`WeightedList`](crate::WeightedList) operations.
28#[derive(Debug)]
29pub struct NumCastError(pub(crate) &'static str);
30
31impl std::fmt::Display for NumCastError
32{
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
34    {
35        write!(f, "{}", self.0)
36    }
37}
38
39impl std::error::Error for NumCastError {}