summary refs log tree commit diff
path: root/library/std/src/path.rs
AgeCommit message (Collapse)AuthorLines
2024-04-28Replace version placeholders for 1.79Mark Rousskov-1/+1
2024-04-26PathBuf: replace transmuting by accessor functionsRalf Jung-7/+1
2024-04-24Stabilize `std::path::absolute`Chris Denton-3/+1
2024-04-17Rollup merge of #122201 - coolreader18:doc-clone_from, r=dtolnayMatthias Krüger-0/+4
Document overrides of `clone_from()` in core/std As mentioned in https://github.com/rust-lang/rust/pull/96979#discussion_r1379502413 Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source". I reused some of the wording over and over for similar impls, but I'm not sure that the wording is actually *good*. Would appreciate feedback about that. Also, now some of these seem to provide pretty specific guarantees about behavior (e.g. will reuse the exact same allocation iff the len is the same), but I was basing it off of the docs for [`Box::clone_from`](https://doc.rust-lang.org/1.75.0/std/boxed/struct.Box.html#method.clone_from-1) - I'm not sure if providing those strong guarantees is actually good or not.
2024-04-10Rework Path::ancestors documentation to remove unwrapsKriskras99-4/+3
If you take a quick glance at the documentation for Path::ancestors, the unwraps take the natural focus. Potentially indicating that ancestors might panic. In the reworked version I've also moved the link with parent returning None and that the iterator will always yield &self to before the yield examples.
2024-04-10Bring documentation of Path::to_path_buf in line with the rest of Path/PathBufKriskras99-2/+2
Changes the example from using the qualified path of PathBuf with an import. This is what's done in all other Path/PathBuf examples and makes the code look a bit cleaner.
2024-03-08Document overrides of `clone_from()`Noa-0/+4
Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source".
2024-02-28Rollup merge of #120051 - riverbl:os-str-display, r=m-ou-seGuillaume Gomez-5/+5
Add `display` method to `OsStr` Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode. Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`. This change also makes the `std::ffi::os_str` module public (see https://github.com/rust-lang/libs-team/issues/326#issuecomment-1894160023). - ACP: https://github.com/rust-lang/libs-team/issues/326 - Tracking issue: #120048
2024-02-22Add `rustc_confusables` annotations to some stdlib APIsEsteban Küber-0/+1
Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` #59450
2024-01-18Add `display` method to `OsStr`riverbl-5/+5
Add `display` method to `OsStr` for lossy display of an `OsStr` which may contain invalid unicode. Invalid Unicode sequences are replaced with `U+FFFD REPLACEMENT CHARACTER`. This change also makes the `std::ffi::os_str` module public.
2023-09-01fix(std): Rename os_str_bytes to encoded_bytesEd Page-17/+17
2023-08-14actually this doesn't even affect doctests. nice.Ralf Jung-12/+6
2023-08-14std: add some missing repr(transparent)Ralf Jung-0/+6
2023-06-27std: remove an allocation in `Path::with_extension`João M. Bezerra-3/+21
`Path::with_extension` used to reallocate (and copy) paths twice per call, now it does it once, by checking the size of the previous and new extensions it's possible to call `PathBuf::with_capacity` and pass the exact capacity it takes. Also reduce the memory consumption of the path returned from `Path::with_extension` by using exact capacity instead of using amortized exponential growth.
2023-05-13refactor: Remove bespoke from_os_str_bytes_uncheckedEd Page-20/+16
2023-05-13refactor: Remove redundant, private OsStr::bytesEd Page-8/+8
2023-05-15Mark internal functions and traits unsafeLegionMammal978-4/+7
2023-05-08Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, ↵bors-1/+1
r=Mark-Simulacrum enable `rust_2018_idioms` lint group for doctests With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests. Resolves #106086 Resolves #99144 Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-1/+1
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-01Rollup merge of #109540 - marcospb19:edit-Path-with_file_name-example, r=m-ou-seMatthias Krüger-5/+11
std docs: edit `PathBuf::set_file_name` example To make explicit that `set_file_name` might replace or remove the extension, not just the file stem. Also edit docs for `Path::with_file_name`, which calls `set_file_name`.
2023-04-28replace version placeholdersPietro Albini-2/+2
2023-04-26Rollup merge of #110266 - tgross35:try-exists-wording, r=jyn514jyn-3/+5
Update documentation wording on path 'try_exists' functions Just eliminate the quadruple negation in `doesn't silently ignore errors unrelated to ... not existing.`
2023-04-14edit docs of `PathBuf::set_file_name`João M. Bezerra-5/+11
to show this method might replace or remove the extension, not just the file stem also edit docs of `Path::with_file_name` because it calls `PathBuf::set_file_name`
2023-04-13Update documentation wording on path 'try_exists' functionsTrevor Gross-3/+5
2023-04-12remove some unneeded importsKaDiWa-21/+21
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>