Skip to content

Consider taking self instead of &self #1

Closed
@calebzulawski

Description

@calebzulawski

I wanted to look into implementing these traits for Iterators, but taking &self makes that a little difficult. With the current traits there isn't a convenient way to implement the following blanket impl:

impl<T: FloatDiff, I: IntoIterator<Item=T>> FloatDiff for I {
    type AbsDiff = AbsDiffIter<T::AbsDiff>;

    fn abs_diff(&self, other: &Self) -> Self::AbsDiff {
        /* can't call self.into_iter() here */
    }

    /* similar for ulps_diff */
}

My proposed changes:

  • Change traits to take self
  • f32, f64, Complex remain unchanged since they are all Copy.
  • Add blanket impls for IntoIterator, returning iterators over AbsDiff, etc.
  • Change implementations for [T; N] to &[T; N] (if they are even still necessary, arrays implement IntoIterator)

Let me know what you think and if you'd like a little help implementing it, I didn't want to go change everything and just drop a PR without bringing it up :)

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