data_structure_traits

Crates.iodata_structure_traits
lib.rsdata_structure_traits
version0.1.12
sourcesrc
created_at2017-09-05 11:15:45.178156
updated_at2018-08-23 01:22:41.456772
descriptiondata structure collection traits
homepagehttps://gitlab.com/nathanfaucett/rs-data_structure_traits
repositoryhttps://gitlab.com/nathanfaucett/rs-data_structure_traits.git
max_upload_size
id30643
size50,600
Nathan Faucett (nathanfaucett)

documentation

https://docs.rs/data_structure_traits

README

data_structure_traits docs

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));
}
Commit count: 47

cargo fmt