hyperledger / iroha

Iroha - A simple, enterprise-grade decentralized ledger
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
425 stars 276 forks source link

Replace usage of `FromStr::from_str` with `str::parse` across the project #4749

Open Stukalov-A-M opened 1 month ago

Stukalov-A-M commented 1 month ago

It's best to use the inherent str::parse<T: FromStr> method across the project instead of FromStr::from_str since it doesn't require bringing FromStr into the scope.

Stukalov-A-M commented 1 month ago

Implemented From<&str>, replace parse to &str

nxsaken commented 1 month ago

@Stukalov-A-M str::parse<T> is more convenient than Into<T>::into in cases where type inference fails, thanks to the turbofish syntax. It is also more idiomatic in this case: FromStr carries the intent of extracting meaning from a string, while (Try)From is more suited for type conversions, where the string probably stays the same but the context around it is changed.

Stukalov-A-M commented 1 month ago

@Stukalov-A-M str::parse<T> is more convenient than Into<T>::into in cases where type inference fails, thanks to the turbofish syntax. It is also more idiomatic in this case: FromStr carries the intent of extracting meaning from a string, while (Try)From is more suited for type conversions, where the string probably stays the same but the context around it is changed.

Could u pls. send the ref where it's said about idiomaticity ?

I found only info that parse::() we're using were cast may bring to an error and Into:: where we sure that str will be casted into the the without errors

nxsaken commented 4 weeks ago

Here are some discussions on it:

If the parsing is infallible, it's possible to specify the empty Infallible type as the Err associated type in FromStr.

Stukalov-A-M commented 4 weeks ago

Here are some discussions on it:

If the parsing is infallible, it's possible to specify the empty Infallible type as the Err associated type in FromStr.

Thanks a lot! I'll research the discussions.