Uh oh!
There was an error while loading. Please reload this page.
Add more ways to create a PathBuf to docs - #41531
Conversation
rust-highfive
commented
Apr 25, 2017
r? @BurntSushi (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Missing link to push method.
There was a problem hiding this comment.
Missing link to push method.
Mark-Simulacrum
commented
Apr 25, 2017
It'd be nice to document how to create a |
There was a problem hiding this comment.
Shouldn't the path be c:\\windows\\system32.dll ?
BTW, on windows we prefer to write the drive letters as uppercase. How about change the path to C:\\Windows\\system32\\user32.dll ? It's a real file path which exists on almost all Windows installations today.
There was a problem hiding this comment.
on windows we prefer to write the drive letters as uppercase.
I thought so too (I'm a Windows user now) but since it was small before, I didn't change it. Happy to do so
Also, if I check in explorer.exe, C:\\windows\ does not load, but C:\windows\ does, so maybe it should be the other way? C:\\windows\\ doesn't load either.
There was a problem hiding this comment.
Since Rust is a language which works on multiple platforms, I think that following the conventions on different platform is useful and important.
Here the \\ is a escape sequence in the path string, so the real path isC:\Windows\ (note the path fragment Windows is capitalized since on Windows the name of this directory is capitailized by default).
There was a problem hiding this comment.
I was thinking of { as escapes in format strings, not \\ as an escape, whoops, heh 😓
nagisa
commented
Apr 26, 2017
via email
I would suggest using raw string to avoid escapes. …On Apr 26, 2017 12:49 PM, "mzji" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/libstd/path.rs
<#41531 (comment)>:
> +/// However, `push` is best used for dynamic situations. This is a better way
+/// to do this when you know all of the components ahead of time:
+///
+/// ```
+/// use std::path::PathBuf;
+///
+/// let path: PathBuf = ["c:\\", "windows", "system32.dll"].iter().collect();
+/// ```
+///
+/// We can still do better than this! Since these are all strings, we can use
+/// `From::from`:
+///
+/// ```
+/// use std::path::PathBuf;
+///
+/// let path = PathBuf::from("c:\\windows\system32.dll");
Here the \\ is a escape sequence in the path string, so the real path *is*
C:\Windows\ (note the path fragment Windows is capitalized since on
Windows the name of this directory is capitailized by default).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#41531 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AApc0rOkpDhRbXAT7voA5o4N1LyTJDM4ks5rzxNEgaJpZM4NHTJ_>
.
|
steveklabnik
commented
May 3, 2017
I plan on updating this PR early next week; sorry about the delay. |
carols10cents
commented
May 8, 2017
Looks like there's a test failure for you to fix when you get back to this o.O: |
I believe I've fixed up everything; let's see what Travis says.
I agree this would be neat, but I don't know how either. I guess |
The best way to do this wasn't in the documentation, and the ways that were there needed some extra text to elaborate. Fixesrust-lang#40159
alexcrichton
commented
May 9, 2017
I'd recommend |
Mark-Simulacrum
commented
May 9, 2017
@alexcrichton The problem there is that it doesn't work as soon as you've filtered or done any other similar iterator operation on |
alexcrichton
commented
May 9, 2017
Ah in that case we have |
| /// ``` | ||
| /// use std::path::PathBuf; | ||
| /// | ||
| /// let path: PathBuf = [r"C:\", "windows", "system32.dll"].iter().collect(); |
There was a problem hiding this comment.
The \ after C: should not be necessary here?
Mark-Simulacrum
commented
May 9, 2017
@alexcrichton No, that doesn't work either (https://is.gd/yG5UPk), since |
Component of a path is always a valid path. The changes to me seem good and I’d r+; it seems to me like discussion about Components could be separate. |
nagisa
commented
May 9, 2017
@bors r+ rollup @Mark-Simulacrum could you please fill a separate issue for |
bors
commented
May 9, 2017
📌 Commit 23382e6 has been approved by |
Mark-Simulacrum
commented
May 9, 2017
Filed #41866. |
Add more ways to create a PathBuf to docs The best way to do this wasn't in the documentation, and the ways that were there needed some extra text to elaborate. Fixesrust-lang#40159 /cc @nagisa
Add more ways to create a PathBuf to docs The best way to do this wasn't in the documentation, and the ways that were there needed some extra text to elaborate. Fixesrust-lang#40159 /cc @nagisa
The best way to do this wasn't in the documentation, and the ways that
were there needed some extra text to elaborate.
Fixes#40159
/cc @nagisa