#statistics #collection #traits #maths

no-std stats_traits

Traits for collection-like types to calculate statistics

1 unstable release

0.1.0 Dec 10, 2022

#2543 in Rust patterns

MIT license

22KB
426 lines

stats

Lines of code MIT License Tests Status CodeFactor Grade

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

Examples

It works on Vectors

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());
}

Dependencies

~150KB