Crates.io | data_structure_traits |
lib.rs | data_structure_traits |
version | 0.1.12 |
source | src |
created_at | 2017-09-05 11:15:45.178156 |
updated_at | 2018-08-23 01:22:41.456772 |
description | data structure collection traits |
homepage | https://gitlab.com/nathanfaucett/rs-data_structure_traits |
repository | https://gitlab.com/nathanfaucett/rs-data_structure_traits.git |
max_upload_size | |
id | 30643 |
size | 50,600 |
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));
}