Change the argument name of From::from

The From trait is currently defined as:

pub trait From<T>: Sized {
    fn from(_: T) -> Self;
}

The name of the argument is _. I am proposing to change it to value, ie.

pub trait From<T>: Sized {
    fn from(value: T) -> Self;
}

This would be more consistent with the TryFrom, which looks like this:

pub trait TryFrom<T>: Sized {
    type Error;
    fn try_from(value: T) -> Result<Self, Self::Error>;
}

The reason for this proposal is twofold:

  1. Consistency with the rest of the standard library. The TryFrom trait uses value, and no From implementation uses the default name (as it is quite useless).
  2. When generating trait implementations with rust-analyzer/IntelliJ, the parameter name is copied, and it always has to be changed.

Optionally, another name like x could be used. I only propose value for consistency with TryFrom.

Changing parameter names is not a breaking change.

13 Likes

I think you can just submit a Pr for this, should be a good first issue!

Ok! I've created #102628.

3 Likes

Sounds great! No matter which name is choosen, it will increase consistency among implementers of From, as many will use the name suggested by rust-analyzer. Beeing constent with TryFrom also makes value a good name.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.