Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Stukalov-A-M opened this issue Jun 20, 2024 · 5 comments
Open
Assignees
Labels
good first issue Good for newcomers iroha2

Comments

@Stukalov-A-M
Copy link
Contributor

Stukalov-A-M commented Jun 20, 2024

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 Stukalov-A-M self-assigned this Jun 20, 2024
@Stukalov-A-M Stukalov-A-M added Documentation Documentation changes iroha2 labels Jun 20, 2024
@nxsaken nxsaken changed the title Remove FromStr trait from integration tests Replace FromStr::from_str with str::parse across the project Jun 20, 2024
@nxsaken nxsaken added the good first issue Good for newcomers label Jun 20, 2024
@nxsaken nxsaken changed the title Replace FromStr::from_str with str::parse across the project Replace usage of FromStr::from_str with str::parse across the project Jun 20, 2024
@nxsaken nxsaken removed the Documentation Documentation changes label Jun 20, 2024
@Stukalov-A-M
Copy link
Contributor Author

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

@nxsaken
Copy link
Contributor

nxsaken commented Jun 27, 2024

@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
Copy link
Contributor Author

@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
Copy link
Contributor

nxsaken commented Jun 27, 2024

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
Copy link
Contributor Author

Stukalov-A-M commented Jun 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers iroha2
Projects
None yet
Development

No branches or pull requests

2 participants