Crates.io | stats_traits |
lib.rs | stats_traits |
version | 0.1.0 |
source | src |
created_at | 2022-12-10 16:52:28.891338 |
updated_at | 2022-12-10 16:52:28.891338 |
description | Traits for collection-like types to calculate statistics |
homepage | |
repository | https://github.com/mrlegohead0x45/stats-traits |
max_upload_size | |
id | 733929 |
size | 24,215 |
stats is a Rust statistics library
The main thing is the Stats
trait which provides all the methods.
It is implemented for all the collection-like types in the standard
library and can be implemented for any type if that type implements
IntoIterator
and Clone
It works on Vec
tors
use stats::Stats;
fn main() {
let my_vec = vec![1, 2, 3];
assert_eq!(my_vec.mean(), 2);
}
To get the methods on your type
use stats::Stats;
#[derive(Clone)]
struct MyStruct {
// ...
};
impl IntoIterator for MyStruct {
// ...
}
impl Stats for MyStruct {}
// Now we can use the methods in `Stats`
fn main() {
let my_struct = MyStruct {};
println!("{}", my_struct.mean());
}