about summary refs log tree commit diff
path: root/library/std/src/path.rs
AgeCommit message (Collapse)AuthorLines
2025-09-30Rollup merge of #142506 - clarfonthey:path-trailing-sep, r=joboetMatthias Krüger-3/+184
Add `Path::has_trailing_sep` and related methods Implements rust-lang/libs-team#335. Tracking issue: rust-lang/rust#142503 Notable differences from ACP: * `trim_trailing_sep` was added to `Path` since it felt reasonable to ensure that the inverse operation was available. * Per suggestion of `@kennytm,` added `push_trailing_sep` and `pop_trailing_sep` to `PathBuf` in addition to `set_trailing_sep`. This also updates some of the docs on various `Path` methods to use the term "trailing separator" instead of "trailing slash" for consistency.
2025-09-26Update CURRENT_RUSTC_VERSION post-bumpMark Rousskov-12/+12
2025-09-24Fix infinite recursion in Path::eq with StringIris Shi-6/+6
2025-09-07docs(std): add error docs for path canonicalizeSoroush Mirzaei-0/+8
2025-09-04Add `Path::has_trailing_sep` and related methodsltdk-3/+184
2025-09-04fixbendn-1/+1
2025-09-04Rollup merge of #145209 - hanna-kruppe:path_add_extension, r=tgross35Stuart Cook-6/+2
Stabilize `path_add_extension` FCP in tracking issue rust-lang/rust#127292 finished in January. There was more discussion since then, but [libs-api decided to match `set_extension`][0] by keeping the return type as-is and adding a panic for invalid extensions. The latter was implemented in rust-lang/rust#140163, so this feature should be ready for stabilization. But if anyone's unsure, another FCP could be done to confirm. Closes rust-lang/rust#127292 [0]: https://github.com/rust-lang/rust/issues/127292#issuecomment-2605197960
2025-09-01Constify conversion traitsltdk-5/+10
2025-08-26remove deprecated Error::description in implsMarijn Schouten-8/+2
2025-08-19Rollup merge of #145464 - Kivooeo:stabilize-const_pathbuf_osstring_new, ↵许杰友 Jieyou Xu (Joe)-1/+1
r=ibraheemdev Stabilize `const_pathbuf_osstring_new` feature This closes [tracking issue](https://github.com/rust-lang/rust/issues/141520) and stabilises `{OsString, PathBuf}::new` in const
2025-08-19Rollup merge of #140956 - Kixunil:impl-partialeq-str-for-path, r=AmanieuStuart Cook-0/+65
`impl PartialEq<{str,String}> for {Path,PathBuf}` This is a revival of #105877 Comparison of paths and strings is expected to be possible and needed e.g. in tests. This change adds the impls os `PartialEq` between strings and paths, both owned and unsized, in both directions. ACP: https://github.com/rust-lang/libs-team/issues/151
2025-08-15stabilize const pathbuf osstring newKivooeo-1/+1
2025-08-13stabilize path_add_extensionHanna Kruppe-6/+2
2025-08-13Rollup merge of #144870 - Kivooeo:file_prefix-stabilize, r=tgross35Jakub Beránek-2/+1
Stabilize `path_file_prefix` feature This stabilises `Path::file_prefix`, following the FCP in [tracking issue ](https://github.com/rust-lang/rust/issues/86319) (FCP ended almost a year ago, so if it's needed for proccess we could rerun it) Closes: https://github.com/rust-lang/rust/issues/86319
2025-08-05add code example showing that file_prefix treats dotfiles as the name of a ↵The 8472-0/+2
file, not an extension
2025-08-04remove gateKivooeo-2/+1
2025-07-25Avoid making the start of a doc code block conditionalJosh Triplett-2/+3
Placing the opening triple-backquote inside a `cfg_attr` makes many tools confused, including syntax highlighters (e.g. vim's) and rustfmt. Instead, use a `cfg` inside the doc code block.
2025-07-07std: fix typo in `std::path`xizheyin-2/+2
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-02Rollup merge of #141847 - xizheyin:141837, r=jhprattMatthias Krüger-2/+4
Explain `TOCTOU` on the top of `std::fs`, and reference it in functions Fixes rust-lang/rust#141837 r? ``````@workingjubilee``````
2025-07-01Update version placeholdersJosh Stone-1/+1
2025-06-19Auto merge of #141864 - Berrysoft:cygwin-path, r=ChrisDentonbors-1/+16
Handle win32 separator for cygwin paths This PR handles a issue that cygwin actually supports Win32 path, so we need to handle the Win32 prefix and separaters. r? `@mati865` cc `@jeremyd2019` ~~Not sure if I should handle the prefix like the windows target... Cygwin *does* support win32 paths directly going through the APIs, but I think it's not the recommended way.~~ Here I just use `cygwin_conv_path` because it handles both cygwin and win32 paths correctly and convert them into absolute POSIX paths. UPDATE: Windows path prefix is handled.
2025-06-16Add documentation for `PathBuf`'s `FromIterator` and `Extend` implsYotam Ofek-0/+27
2025-06-16Handle win32 separator & prefixes for cygwin paths王宇逸-1/+16
2025-06-06Stabilised `os_string_pathbuf_leak`schvv31n-1/+1
2025-06-04Rollup merge of #141467 - cyrgani:const-empty-stringlikes, r=AmanieuMatthias Krüger-1/+2
make `OsString::new` and `PathBuf::new` unstably const Since #129041, `String::into_bytes` is `const`, which allows making `OsString::new` and `PathBuf::new` unstably const now. Not sure what the exact process for this is; does it need an ACP?
2025-06-02Explain TOCTOU on the top of `std::fs`, and ref it in functionsxizheyin-2/+4
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn> Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-29Rollup merge of #141477 - tshepang:patch-1, r=ChrisDentonJacob Pratt-5/+20
Path::with_extension: show that it adds an extension where one did no… …t exist I think the times I encountered this, I had to check first if files without extensions were added, since all examples only had files with existing extensions. Also, this replaced example already has a similar example below.
2025-05-25Implement normalize lexicallyChris Denton-0/+77
2025-05-24make `OsString::new` and `PathBuf::new` unstably constcyrgani-1/+2
2025-05-24reduce clutter... too many importsTshepang Mbambo-8/+8
2025-05-24Path::with_extension: improve examplesTshepang Mbambo-1/+16
2025-05-20use Self alias in self types rather than manually substituting itMichael Goulet-1/+1
2025-05-13`impl PartialEq<{str,String}> for {Path,PathBuf}`Martin Habovstiak-0/+65
Comparison of paths and strings is expected to be possible and needed e.g. in tests. This change adds the impls os `PartialEq` between strings and paths, both owned and unsized, in both directions. ACP: https://github.com/rust-lang/libs-team/issues/151
2025-05-02Rollup merge of #140159 - thaliaarchi:pathbuf-extension, r=workingjubileeStuart Cook-7/+12
Avoid redundant WTF-8 checks in `PathBuf` Eliminate checks for WTF-8 boundaries in `PathBuf::set_extension` and `add_extension`, where joining WTF-8 surrogate halves is impossible. Don't convert the `str` to `OsStr`, because `OsString::push` specializes to skip the joining when given strings. To assist in this, mark the internal methods `OsString::truncate` and `extend_from_slice` as `unsafe` to communicate their safety invariants better than with module privacy. Similar to #137777. cc `@joboet` `@ChrisDenton`
2025-04-30Avoid redundant WTF-8 checks in `PathBuf`Thalia Archibald-6/+10
Eliminate checks for WTF-8 boundaries in `PathBuf::set_extension` and `add_extension`, where joining WTF-8 surrogate halves is impossible. Don't convert the `str` to `OsStr`, because `OsString::push` specializes to skip the joining when given strings.
2025-04-30Make internal `OsString::truncate` and `extend_from_slice` unsafeThalia Archibald-1/+2
Communicate the safety invariants of these methods with `unsafe fn` rather than privacy.
2025-04-22Validate extension in `PathBuf::add_extension`Thalia Archibald-7/+17
The extension is validated in `PathBuf::set_extension`, but not `add_extension`. Fix that. Check for both / and \ path separators on Windows, even when the path is verbatim, since this is logically like `PathBuf::push` which normalizes separators (i.e., keeping the current behavior).
2025-04-21cleanup redundant pattern instancesJonathan Gruner-1/+1
2025-03-13Remove has_redox_schemebjorn3-7/+1
Redox OS is moving away from name:/path style paths to /scheme/name/path style paths which are already handled correctly without has_redox_scheme.
2025-02-10Fix &&str and trailing commas in io::const_error!Thalia Archibald-1/+1
2025-01-26Move std::path unit tests to integration testsbjorn3-3/+0
2025-01-13path: Move is_absolute check to sys::pathAyush Singh-11/+4
I am working on fs support for UEFI [0], which similar to windows has prefix components, but is not quite same as Windows. It also seems that Prefix is tied closely to Windows and cannot really be extended [1]. This PR just tries to remove coupling between Prefix and absolute path checking to allow platforms to provide there own implementation to check if a path is absolute or not. I am not sure if any platform other than windows currently uses Prefix, so I have kept the path.prefix().is_some() check in most cases. [0]: https://github.com/rust-lang/rust/pull/135368 [1]: https://github.com/rust-lang/rust/issues/52331#issuecomment-2492796137 Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2024-12-13Fix `Path::is_absolute` on HermitMartin Kröning-1/+3
2024-12-01Rollup merge of #133602 - SanchithHegde:fix-pathbuf-example-codeblocks, ↵Matthias Krüger-0/+2
r=cuviper fix: fix codeblocks in `PathBuf` example This PR adds missing codeblocks around an example included in the `PathBuf` documentation.
2024-11-29fix: fix codeblocks in `PathBuf` exampleSanchith Hegde-0/+2
2024-11-27replace placeholder versionBoxy-3/+3
2024-11-27Rollup merge of #133449 - joboet:io_const_error, r=tgross35Matthias Krüger-1/+1
std: expose `const_io_error!` as `const_error!` ACP: https://github.com/rust-lang/libs-team/issues/205 Tracking issue: https://github.com/rust-lang/rust/issues/133448 Probably best reviewed commit-by-commit, the first one does the API change, the second does the mass-rename.
2024-11-26std: update internal uses of `io::const_error!`joboet-1/+1
2024-11-24Added a doc test for std::path::strip_prefixCrom (Thibaut CHARLES)-0/+1
2024-11-12Make `CloneToUninit` dyn-compatibleZachary S-4/+4