These are chat archives for rust-lang/rust

23rd
Jun 2017
stevensonmt
@stevensonmt
Jun 23 2017 03:23
fn mean(v: Vec<u32>) {
    let sum: u32 = v.iter().take(v.len()).sum();
    sum/(v.len() as u32);

}

fn main() {
    println!("{:?}", mean(vec![1,2,3]));

}
why doesn't my mean function return the value of sum/v.len() instead of ()?
stevensonmt
@stevensonmt
Jun 23 2017 04:04
figured it out.
pub fn mean(v: Vec<u32>) -> u32 {
    let sum: u32 = v.iter().take(v.len()).sum();
    sum/(v.len() as u32)
}

fn main() {
    println!("{:?}", mean(vec![1,2,3]));
}
Michal 'vorner' Vaner
@vorner
Jun 23 2017 17:28
Hello. Does Rust have something like a „shouldn't compile“ test? As a nice API would make invalid inputs/states/etc unrepresentable, it should be nice to actually test that it does so.
Ilya Bogdanov
@vitvakatu
Jun 23 2017 17:30
There's only "should fail at runtime" tests
Michal 'vorner' Vaner
@vorner
Jun 23 2017 18:16
@bwasty Thanks, I'll look into that. It looks it's what I'm looking for at the first glance.
Jonas Platte
@jplatte
Jun 23 2017 18:31
@stevensonmt Why do you have .take(v.len()) in there?
stevensonmt
@stevensonmt
Jun 23 2017 19:39
Good point. Thanks.
Nikolay Denev
@ndenev
Jun 23 2017 19:57
Looks like RLS with the latest nightly is crashing a lot.
Missing change, aborting. Found 172, expected Some(173)
ah, there's an issue already : rust-lang-nursery/rls#372