about summary refs log tree commit diff
path: root/library/std/src/path.rs
AgeCommit message (Collapse)AuthorLines
2023-03-10Rollup merge of #105962 - zertosh:stabilize_path_as_mut_os_str, r=dtolnayMatthias Krüger-4/+2
Stabilize path_as_mut_os_str Closes #105021 r? ```@dtolnay```
2023-01-31Auto merge of #107297 - Mark-Simulacrum:bump-bootstrap, r=pietroalbinibors-2/+2
Bump bootstrap compiler to 1.68 This also changes our stage0.json to include the rustc component for the rustfmt pinned nightly toolchain, which is currently necessary due to rustfmt dynamically linking to that toolchain's librustc_driver and libstd. r? `@pietroalbini`
2023-01-31fix link in std::path::Path::display()Lucius Hu-0/+1
The link `Debug` points to should be the trait `Debug`, not the macro `Debug`.
2023-01-25Set version placeholders to 1.68Mark Rousskov-2/+2
2023-01-20add example of joining with a absolute pathValdemar Erk-0/+1
2023-01-20Add note about absolute paths to Path::joinValdemar Erk-0/+2
2023-01-14Remove various double spaces in source comments.André Vennberg-1/+1
2023-01-12Stop having unused lifetimes on some `impl`sScott McMurray-29/+29
2023-01-08Rollup merge of #103104 - SUPERCILEX:sep-ref, r=dtolnayYuki Okushi-1/+1
Stabilize `main_separator_str` See reasoning here: https://github.com/rust-lang/rust/issues/94071#issuecomment-1279872605. Closes #94071.
2023-01-02Rollup merge of #104298 - tbu-:pr_set_extension_caveats, r=m-ou-seMichael Goulet-3/+30
Add notes and examples about non-intuitive `PathBuf::set_extension` behavior Basically, passing the empty string will actually remove the extension instead of setting it to the empty string. This might change what is considered to be an extension. Additionally, passing an extension that contains dots will make the path only consider the last part of it to be the new extension.
2022-12-31Rollup merge of #106280 - Ezrashaw:path-join-docs-better, r=thomccMatthias Krüger-0/+3
docs: add link to `Path::join` in `PathBuf::push` Fixes #106219 Hopefully my wording is alright.
2022-12-31Add notes and examples about non-intuitive `PathBuf::set_extension` behaviorTobias Bucher-3/+30
Basically, passing the empty string will actually remove the extension instead of setting it to the empty string. This might change what is considered to be an extension. Additionally, passing an extension that contains dots will make the path only consider the last part of it to be the new extension.
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-1/+1
2022-12-30docs: add link to `Path::join` in `PathBuf::push`Ezra Shaw-0/+3
2022-12-20Stabilize path_as_mut_os_strAndres Suarez-4/+2
Closes #105021
2022-12-16Realistic `Path::as_mut_os_str` doctestAndres Suarez-3/+3
2022-12-16Auto merge of #105018 - zertosh:path_buf_deref_mut, r=dtolnaybors-0/+14
Implement DerefMut for PathBuf Without this, there's no way to get a `&mut Path` from `PathBuf` without going through `into_boxed_path`. This is relevant now that #105002 adds `PathBuf::as_mut_os_string` and `Path::as_mut_os_str`.
2022-11-28Add `as_mut_os_string` to `&mut PathBuf` and `as_mut_os_str` to `&mut Path`Andres Suarez-0/+46
Implements rust-lang/libs-team#140
2022-11-28Implement DerefMut for PathBufAndres Suarez-0/+14
2022-11-11Document `Path::parent` behavior around relative pathsTobias Bucher-1/+12
A relative path with just one component will return `Some("")` as its parent, which wasn't clear to me from the documentation. The parent of `""` is `None`, which was missing from the documentation as well.
2022-10-15Stabilize `main_separator_str`Alex Saveau-1/+1
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-09Add basename and dirname aliasesAriel Davis-0/+2
2022-09-20Clarify Path::extension() semantics in docs abstractMahmoud Al-Qudsi-1/+1
State up-front and center what shape the returned extension will have, without making the user read through the description and examples. Rationale: Various frameworks and libraries for different platforms have their different conventions as to whether an "extension" is ".ext" or just "ext" and anyone that's had to deal with this ambiguity in the past is always double- or triple-checking to make sure the function call returns an extension that matches the expected semantics. Offer the answer to this important question right off the bat instead of making them dig to find it.
2022-06-20Rollup merge of #97912 - Kixunil:stabilize_path_try_exists, r=dtolnayYuki Okushi-6/+11
Stabilize `Path::try_exists()` and improve doc This stabilizes the `Path::try_exists()` method which returns `Result<bool, io::Error>` instead of `bool` allowing handling of errors unrelated to the file not existing. (e.g permission errors) Along with the stabilization it also: * Warns that the `exists()` method is error-prone and suggests to use the newly stabilized one. * Suggests it instead of `metadata()` to handle errors. * Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is completely safe fixed version of `exists()`. * Renames the feature of still-unstable `std::fs::try_exists()` to `fs_try_exists` to avoid name conflict. The tracking issue #83186 remains open to track `fs_try_exists`.
2022-06-16std: Stabilize feature try_reserve_2Xuanwo-2/+2
Signed-off-by: Xuanwo <github@xuanwo.io>
2022-06-14Stabilize `Path::try_exists()` and improve docMartin Habovstiak-6/+11
This stabilizes the `Path::try_exists()` method which returns `Result<bool, io::Error>` instead of `bool` allowing handling of errors unrelated to the file not existing. (e.g permission errors) Along with the stabilization it also: * Warns that the `exists()` method is error-prone and suggests to use the newly stabilized one. * Suggests it instead of `metadata()` to handle errors. * Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is completely safe fixed version of `exists()`. * Renames the feature of still-unstable `std::fs::try_exists()` to `fs_try_exists` to avoid name conflict. The tracking issue #83186 remains open to track `fs_try_exists`.
2022-05-08fix panic in Path::strip_prefixname1e5s-1/+1
2022-04-17Remove unnecessary functiondylni-20/+18
2022-04-17Improve Windows path prefix parsingdylni-2/+2
2022-03-29Make the stdlib largely conform to strict provenance.Aria Beingessner-2/+2
Some things like the unwinders and system APIs are not fully conformant, this only covers a lot of low-hanging fruit.
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-1/+1
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-17Rollup merge of #93976 - SUPERCILEX:separator_str, r=yaahcMatthias Krüger-0/+6
Add MAIN_SEPARATOR_STR Currently, if someone needs access to the path separator as a str, they need to go through this mess: ```rust unsafe { std::str::from_utf8_unchecked(slice::from_ref(&(MAIN_SEPARATOR as u8))) } ``` This PR just re-exports an existing path separator str API.
2022-02-17Rollup merge of #89869 - kpreid:from-doc, r=yaahcMatthias Krüger-3/+3
Add documentation to more `From::from` implementations. For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy. Notes on specific cases: * The new documentation for `From<T> for T` explains that it is not a conversion at all. * Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion. * The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set. * I did not add documentation to conversions of a specific error type to a more general error type. * I did not add documentation to unstable code. This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
2022-02-16Add MAIN_SEPARATOR_STRAlex Saveau-0/+6
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-02-13Auto merge of #91673 - ChrisDenton:path-absolute, r=Mark-Simulacrumbors-1/+77
`std::path::absolute` Implements #59117 by adding a `std::path::absolute` function that creates an absolute path without reading the filesystem. This is intended to be a drop-in replacement for [`std::fs::canonicalize`](https://doc.rust-lang.org/std/fs/fn.canonicalize.html) in cases where it isn't necessary to resolve symlinks. It can be used on paths that don't exist or where resolving symlinks is unwanted. It can also be used to avoid circumstances where `canonicalize` might otherwise fail. On Windows this is a wrapper around [`GetFullPathNameW`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew). On Unix it partially implements the POSIX [pathname resolution](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13) specification, stopping just short of actually resolving symlinks.
2022-02-12Auto merge of #93697 - the8472:fix-windows-path-hash, r=Mark-Simulacrumbors-9/+17
Fix hashing for windows paths containing a CurDir component * the logic only checked for / but not for \ * verbatim paths shouldn't skip items at all since they don't get normalized * the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false * tests lacked windows coverage for these cases That lead to equal paths not having equal hashes and to unnecessary collisions.
2022-02-08Fix `absolute` issuesChris Denton-2/+2
2022-02-08`std::path::absolute`Chris Denton-1/+77
2022-02-06Fix hashing for windows paths containing a CurDir componentThe 8472-9/+17
* the logic only checked for / but not for \ * verbatim paths shouldn't skip items at all since they don't get normalized * the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false * tests lacked windows coverage for these cases That lead to equal paths not having equal hashes and to unnecessary collisions.
2022-02-01Link `try_exists` docs to `Path::exists`Chris Denton-1/+3
2022-01-24Rollup merge of #92513 - Xuanwo:path-buf, r=dtolnayMatthias Krüger-0/+19
std: Implement try_reserve and try_reserve_exact on PathBuf Part of https://github.com/rust-lang/rust/issues/91789 Signed-off-by: Xuanwo <github@xuanwo.io>
2022-01-20Correct docs in `Arc` and `Rc`.Jakob Degen-3/+5
A number of trait implementations incorrectly claimed to be zero cost.
2022-01-14Typos fixMaxwase-1/+1
2022-01-03std: Implement try_reserve and try_reserve_exact on PathBufXuanwo-0/+19
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-11Correct since attribute for featureMaxwase-1/+1
2021-12-04Add documentation to more `From::from` implementations.Kevin Reid-3/+3
For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy. Notes on specific cases: * The new documentation for `From<T> for T` explains that it is not a conversion at all. * Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion. * I did not add documentation to conversions of a specific error type to a more general error type. * I did not add documentation to unstable code. This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
2021-12-02Document file path case sensitivityChris Denton-0/+7
2021-11-11`Prefix` can be case-insensitive, delegate to its Hash impl instead of ↵The8472-0/+8
trying to hash the raw bytes This should have 0 performance overhead on unix since Prefix is always None.
2021-11-09remove redundant .iter() call since zip() takes an IntoIterator argumentThe8472-6/+5
2021-11-09add fast path on Path::eq for exact equalityThe8472-1/+20