Skip to content

warn_self_convention and copy? #273

@wackywendell

Description

@wackywendell

I recently got a warn_self_convention lint on a type that implements Copy, something like this:

#[derive(Copy)]
pub struct Color(pub u8, pub u8, pub u8);

impl Color {
    /// Convert to a 3-tuple, from 0 to 1
    pub fn as_floats(self) -> (f32, f32, f32) {
        let Color(r,g,b) = self;
        (
            (r as f32) / (u8::max_value() as f32),
            (g as f32) / (u8::max_value() as f32),
            (b as f32) / (u8::max_value() as f32),
        )
    }
src/palette.rs:43:22: 43:30 warning: methods called `as_*` usually take self by reference; consider choosing a less ambiguous name, #[warn(wrong_self_convention)] on by default
src/palette.rs:43     pub fn as_floats(self) -> (f32, f32, f32) {

It seems to me that types that implement Copy should be permitted to use pass-by-value instead of pass-by-reference for as_, to_, and other such methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions