camino-rs / camino

Like Rust's std::path::Path, but UTF-8.
https://docs.rs/camino
Apache License 2.0
435 stars 16 forks source link

Idea: Add camino::absolute() #94

Closed noamraph closed 2 months ago

noamraph commented 2 months ago

Currently in order to get the absolute path of a Utf8Path, it seems that I need to do:

Utf8PathBuf::from_path_buf(absolute(path)?).unwrap()

How about adding an absolute() function to camino?

I'll be happy to try to write a PR if you approve of the idea.

Thanks! Noam

sunshowers commented 2 months ago

Thanks for the suggestion! "absolute" can mean several things depending on the context. The closest thing currently supported is canonicalize and the related canonicalize_utf8.

In general camino follows Rust's Path API, so I'd be hesitant to add methods that aren't already in Rust's Path. But you're welcome to have your own function, of course.

noamraph commented 2 months ago

I now see I didn't mention the standard Rust API. I meant to follow's Rust's std::path::absolute, without inventing any new API. Does that seem like a good idea?

sunshowers commented 2 months ago

Oh, gotcha! Yeah that makes sense then.

sunshowers commented 2 months ago

This is now out in camino 1.1.9. Thanks for the issue!

sunshowers commented 2 months ago

I'll be happy to try to write a PR if you approve of the idea.

Ohhh I just noticed this, sorry! I'd love a future contribution from you if you ever have an idea. Thanks!

noamraph commented 2 months ago

Ohhh I just noticed this, sorry! I'd love a future contribution from you if you ever have an idea. Thanks!

Thanks! Really no problem, it would surely have taken longer if I had tried to implement it. For example, I wouldn't have thought of adding the Rust version check. So thanks for adding this so quickly!