JelteF / derive_more

Some more derive(Trait) options
MIT License
1.73k stars 123 forks source link

Typo / confusing wording in From docs #375

Closed joshka closed 4 months ago

joshka commented 4 months ago

At https://jeltef.github.io/derive_more/derive_more/from.html,

When deriving for a tuple struct with a single field (i.e. a newtype) like this:

#[derive(From)]
struct MyInt(i32);

Code like this will be generated:

impl ::core::convert::From<(i32)> for MyInt {
   fn from(original: (i32)) -> MyInt {
       MyInt(original)
   }
}

The extra parentheses around i32 are confusing although this means the exact same thing as without the parentheses, this implies a tuple which would be represented as (i32,) here. I'd suggest replacing this with the following for better clarity:

impl ::core::convert::From<i32> for MyInt {
    fn from(original: i32) -> MyInt {
        MyInt(original)
    }
}

Alternatively make a note about how (x) is not the same as (x,) here.

Note this also applies to other examples in the same doc.

JelteF commented 4 months ago

Sounds reasonable, could you create a PR for the docs?

joshka commented 4 months ago

Yep, sure. I'm a little confused about the branching strategy you're using. Which branch are these docs coming from?

JelteF commented 4 months ago

Just the master branch (but the current master branch has many changes)

joshka commented 4 months ago

Ok, the docs in master are different and don't have this info anymore.

JelteF commented 4 months ago

Okay closing this issue then.