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

Feature request: Cow<'a, str> conversions #39

Open
indygreg opened this issue Nov 13, 2022 · 1 comment
Open

Feature request: Cow<'a, str> conversions #39

indygreg opened this issue Nov 13, 2022 · 1 comment

Comments

@indygreg
Copy link

Thanks for this terrific crate!

I found myself needing to convert between Cow<'a, str> and Cow<'a, Utf8Path>. This is a bit awkward with the current crate APIs because you need to explicitly construct a Cow or Utf8Path/Utf8PathBuf at the call site. I'd prefer to e.g. just .into() on a Cow<'a, str> to get a Cow<'a, Utf8Path>.

What do you think about adding explicit Cow<'a, str> type conversions to Utf8Path and Utf8PathBuf?

@sunshowers
Copy link
Collaborator

Thanks for the kind words!

Sadly that isn't possible via From directly:

error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
    --> src/lib.rs:2253:1
     |
2253 | impl<'a> From<Cow<'a, str>> for Cow<'a, Utf8Path> {
     | ^^^^^^^^^------------------^^^^^-----------------
     | |        |                      |
     | |        |                      `Cow` is not defined in the current crate
     | |        `Cow` is not defined in the current crate
     | impl doesn't use only types from inside the current crate
     |
     = note: define and implement a trait or new type instead

For more information about this error, try `rustc --explain E0117`.
error: could not compile `camino` due to previous error

I guess we could add explicit methods to do this. Not sure what to call them.

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

No branches or pull requests

2 participants