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

feat!: function can take owned 'AsRef<Path>' instead of borrow #51

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

woshilapin
Copy link
Contributor

AsRef<U> is implemented for any &T when T does implement AsRef<U> too. Therefore, we can leave to the caller the decision to give an owned value or a borrowed value, as long as the type implements AsRef<Path>, the borrowed type will too.

I feel that it's more natural, since you can then give a String, a &str, which avoids things like read(&"my_file.txt") instead of read("my_file.txt").

What do you think?

`AsRef<U>` is implemented for any `&T` when `T` does implement `AsRef<U>` too.
Therefore, we can leave to the caller the decision to give an owned value or
a borrowed value, as long as the type implements `AsRef<Path>`, the borrowed
type will too.

I feel that it's more natural, since you can then give a `String`, a `&str`,
which avoids things like `read(&"my_file.txt")` instead of `read("my_file.txt")`.

What do you think?
Copy link
Collaborator

@Tristramg Tristramg left a comment

Choose a reason for hiding this comment

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

Thank you! This makes a lot of sense.

(out of curiosity, did have to touch that crate ?)

@Tristramg Tristramg merged commit 089c658 into rust-transit:main Oct 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants