I am trying to run following rust source file as script using cargo-script:
// cargo-deps: statistical
extern crate statistical;
use statistical::*;
fn main() {
let alist = [10, 20, 30, 40, 50];
println!("mean of list: {}", mean(&alist)); // not working
}
However, I am getting following error:
$ cargo script mystats.rs
Updating crates.io index
Compiling mystats v0.1.0 (/home/abcde/.cargo/script-cache/file-mystats-6e38bab8b3f0569c)
error[E0277]: the trait bound `{integer}: num_traits::float::Float` is not satisfied
--> mystats.rs:7:31
|
7 | println!("mean of list: {}", mean(&alist)); // not working
| ^^^^ the trait `num_traits::float::Float` is not implemented for `{integer}`
|
= help: the following implementations were found:
<f32 as num_traits::float::Float>
<f64 as num_traits::float::Float>
= note: required by `statistical::mean`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: Could not compile `mystats`.
To learn more, run the command again with --verbose.
internal error: cargo failed with status 101
How can this integer/float problem be solved?
meanis a little bit quirky, because I see no reason why they can't accept something likefn mean<I: Float>(p: impl Iterator<Item = I>) -> I;and you were not forced to pass a slice