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

Implement FromStr for NodePath #201

Merged
merged 1 commit into from
Mar 23, 2023
Merged

Conversation

juliohq
Copy link
Contributor

@juliohq juliohq commented Mar 23, 2023

Implements FromStr for NodePath.

@Bromeon
Copy link
Member

Bromeon commented Mar 23, 2023

Nothing generally against it, but what is your motivating use case, which isn't already satisfied by From<&str>?

@Bromeon Bromeon added feature Adds functionality to the library c: core Core components labels Mar 23, 2023
@juliohq
Copy link
Contributor Author

juliohq commented Mar 23, 2023

Nothing generally against it, but what is your motivating use case, which isn't already satisfied by From<&str>?

It's more clear/explicit since into can be an overloaded function, and some methods (like str::parse) use the FromStr trait.

@Bromeon
Copy link
Member

Bromeon commented Mar 23, 2023

It needs unwrap() though, which is arguably less clear 😉
But it's good, just one comment -- please amend your existing commit (1 in total), thanks!

bors try

bors bot added a commit that referenced this pull request Mar 23, 2023
@bors
Copy link
Contributor

bors bot commented Mar 23, 2023

try

Build succeeded:

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, forgot to send the actual comment.

type Err = ();

fn from_str(path: &str) -> Result<Self, ()> {
Ok(Self::from(&GodotString::from(path)))
Copy link
Member

@Bromeon Bromeon Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you call Self::from(path) directly?

There is a From<&str> that we can reuse 🙂

@juliohq juliohq force-pushed the node-path-from-str branch from 86f09f5 to 88c7c64 Compare March 23, 2023 15:20
@@ -60,6 +61,15 @@ impl From<&str> for NodePath {
}
}

// TODO: Check if it's required to implement Err
impl FromStr for NodePath {
type Err = ();
Copy link
Member

@Bromeon Bromeon Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, something else -- this should probably be Infallible, no? () means there is a value for errors, however we want to have no value as it always succeeds.

This is also what String::from_str does.

You can then remove the TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense to use Infallible there too.

@juliohq juliohq force-pushed the node-path-from-str branch from 88c7c64 to 0556d52 Compare March 23, 2023 15:45
@Bromeon
Copy link
Member

Bromeon commented Mar 23, 2023

Thanks a lot!

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 23, 2023

Build succeeded:

@bors bors bot merged commit afa2e59 into godot-rust:master Mar 23, 2023
@juliohq juliohq deleted the node-path-from-str branch March 23, 2023 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: core Core components feature Adds functionality to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants