dhardy
1
Right now, creating a Path
from a temporary String
is a two-liner:
fn create_temporary_string() -> String { ... }
let path_str = create_temporary_string();
let path = Path::new(&path_str);
Would there be interest in adding the following, or is it two much clutter to avoid an extra line of user code?
let path = Path::from_string(create_temporary_string());
If there’s interest, I’ll go ahead and create a PR (I presume this doesn’t need a full RFC).
I might be missing something, but given that Path
is a borrowed type, how can this possibly work?
2 Likes
gkoz
3
To expand on that, why not do
let path = PathBuf::from(create_temporary_string());
2 Likes
@dhardy I assume you’re proposing this due to the lifetime problem with
let path = Path::new(&create_temporary_string());
@DanielKeep is right that Path::from_string
is not possible to implement, and @gkoz’s alternative is correct.
dhardy
5
I didn’t realise that was how Path
works. Thanks for the corrections.
system
Closed
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.