13 releases
Uses old Rust 2015
0.1.12 | Aug 23, 2018 |
---|---|
0.1.11 | Aug 21, 2018 |
0.1.8 | Dec 7, 2017 |
0.1.7 | Nov 6, 2017 |
0.1.1 | Sep 11, 2017 |
#1466 in Data structures
37 downloads per month
Used in immut_list
37KB
1.5K
SLoC
data_structure_traits
data structure collection traits
#[macro_use]
extern crate data_structure_traits;
use data_structure_traits::*;
fn use_seq<'a, S>(s: &'a mut S) -> f32
where
S: SeqMut<'a, f32>,
&'a S: IntoIterator<Item = &'a f32>,
&'a mut S: IntoIterator<Item = &'a mut f32>,
{
if s.len() >= 5 {
s.get_mut(4).map(|v| {
*v = 0.0;
});
} else {
s.insert(0, 1.0);
}
let mut avg = 0.0;
let len = s.len();
for v in s.into_iter() {
avg += *v;
}
avg / (len as f32)
}
fn main() {
let mut v: Vec<f32> = collection![0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0];
println!("{:?}", use_seq(&mut v));
}
Dependencies
~45KB