Skip to content

Is there a reason parameters are Iterators instead of IntoIterator? #14

@FelixBenning

Description

@FelixBenning

If I understand what I am doing, then, if

pub fn mean<I>(it: I) -> f64 where
    I: Iterator,
    <I as Iterator>::Item: ToPrimitive, 

was changed to something like

fn mean<'a, I, T>(x:I)-> f64 where
    I: IntoIterator<Item= T>,
    T: Into<&'a f64>
{
   let it = x.into_iter();
   ...
}

You could also use mean on vectors. e.g.

mean(&vec![1,2,3])

as opposed to

mean(vec![1,2,3].iter().collect())

without losing any functionality for iterators themselves. But I am just learning Rust, so I might not understand some limitation of this approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions