about summary refs log tree commit diff
path: root/library/std/src/path.rs
AgeCommit message (Collapse)AuthorLines
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
2021-11-09optimize Hash for PathThe8472-2/+28
Hashing does not have to use the whole Components parsing machinery because we only need it to match the normalizations that Components does. * stripping redundant separators -> skipping separators * stripping redundant '.' directories -> skipping '.' following after a separator That's all it takes. And instead of hashing individual slices for each component we feed the bytes directly into the hasher which avoids hashing the length of each component in addition to its contents.
2021-10-31Rollup merge of #90431 - jkugelman:must-use-std-o-through-z, r=joshtriplettMatthias Krüger-0/+15
Add #[must_use] to remaining std functions (O-Z) I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from O-Z. `panicking::take_hook` has a side effect: it unregisters the current panic hook, returning it. I almost ignored it, but the documentation example shows `let _ = panic::take_hook();`, so following suit I went ahead and added a `#[must_use]`. ```rust std::panicking fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>; ``` I added these functions that clippy did not flag: ```rust std::path::Path fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool; std::path::Path fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool; std::path::Path fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> PathBuf; std::path::Path fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf; ``` Parent issue: #89692 r? `@joshtriplett`
2021-10-31Rollup merge of #89677 - maxwase:is-symlink-stabilization, r=joshtriplettMatthias Krüger-3/+8
Stabilize `is_symlink()` for `Metadata` and `Path` I'm not fully sure about `since` version, correct me if I'm wrong Needs update after stabilization: [cargo-test-support](https://github.com/rust-lang/cargo/blob/8063672238a5b6c3a901c0fc17f3164692d0be85/crates/cargo-test-support/src/paths.rs#L202) Linked issue: #85748
2021-10-30Add #[must_use] to remaining std functions (O-Z)John Kugelman-0/+15
2021-10-14Ensure that pushing empty path works as beforeSean Young-1/+4
Fixes: https://github.com/rust-lang/rust/issues/89658
2021-10-13Rollup merge of #89794 - jkugelman:must-use-to_value-conversions, r=joshtriplettYuki Okushi-0/+6
Add #[must_use] to to_value conversions `NonNull<T>::cast` snuck in when I wasn't looking. What a scamp! Parent issue: #89692 r? ````@joshtriplett````
2021-10-13Merge branch 'master' into is-symlink-stabilizationMax Wase-0/+20
2021-10-12Rollup merge of #89797 - jkugelman:must-use-is_condition-tests, r=joshtriplettthe8472-0/+8
Add #[must_use] to is_condition tests I threw in `std::path::Path::has_root` for funsies. A continuation of #89718. Parent issue: #89692 r? ```@joshtriplett```
2021-10-12Rollup merge of #89796 - jkugelman:must-use-non-mutating-verb-methods, ↵the8472-0/+2
r=joshtriplett Add #[must_use] to non-mutating verb methods These are methods that could be misconstrued to mutate their input, similar to #89694. I gave each one a different custom message. I wrote that `upgrade` and `downgrade` don't modify the input pointers. Logically they don't, but technically they do... Parent issue: #89692 r? ```@joshtriplett```
2021-10-12Rollup merge of #89778 - jkugelman:must-use-as_type-conversions, r=joshtriplettthe8472-0/+5
Add #[must_use] to as_type conversions Clippy missed these: ```rust alloc::string::String fn as_mut_str(&mut self) -> &mut str; core::mem::NonNull<T> unsafe fn as_uninit_mut<'a>(&mut self) -> &'a MaybeUninit<T>; str unsafe fn as_bytes_mut(&mut self) -> &mut [u8]; str fn as_mut_ptr(&mut self) -> *mut u8; ``` Parent issue: #89692 r? ````@joshtriplett````
2021-10-12Update library/std/src/path.rsMax Wase-0/+6
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
2021-10-11Add #[must_use] to non-mutating verb methodsJohn Kugelman-0/+2
2021-10-11Add #[must_use] to is_condition testsJohn Kugelman-0/+8
A continuation of #89718.
2021-10-11Add #[must_use] to to_value conversionsJohn Kugelman-0/+6
2021-10-11Add #[must_use] to as_type conversionsJohn Kugelman-0/+5
2021-10-11Rollup merge of #89729 - jkugelman:must-use-core-std-constructors, ↵Guillaume Gomez-0/+2
r=joshtriplett Add #[must_use] to core and std constructors Parent issue: #89692 r? ``@joshtriplett``
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-0/+3
2021-10-10Add #[must_use] to core and std constructorsJohn Kugelman-0/+2
2021-10-08Stabilize `is_symlink()` for `Metadata` and `Path`Maxwase-3/+2
2021-10-01path.push() should work as expected on windows verbatim pathsSean Young-7/+46
2021-09-25Apply 16 commits (squashed)Frank Steffahn-1/+1
---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::fmt ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::{rc, sync} ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::string ---------- Fix spacing for links inside code blocks in alloc::vec ---------- Fix spacing for links inside code blocks in core::option ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in core::result ---------- Fix spacing for links inside code blocks in core::{iter::{self, iterator}, stream::stream, poll} ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{fs, path} ---------- Fix spacing for links inside code blocks in std::{collections, time} ---------- Fix spacing for links inside code blocks in and make formatting of `&str`-like types consistent in std::ffi::{c_str, os_str} ---------- Fix spacing for links inside code blocks, and improve link tooltips in std::ffi ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{io::{self, buffered::{bufreader, bufwriter}, cursor, util}, net::{self, addr}} ---------- Fix typo in link to `into` for `OsString` docs ---------- Remove tooltips that will probably become redundant in the future ---------- Apply suggestions from code review Replacing `…std/primitive.reference.html` paths with just `reference` Co-authored-by: Joshua Nelson <github@jyn.dev> ---------- Also replace `…std/primitive.reference.html` paths with just `reference` in `core::pin`
2021-08-22Auto merge of #85166 - mbhall88:file-prefix, r=dtolnaybors-3/+62
add file_prefix method to std::path This is an initial implementation of `std::path::Path::file_prefix`. It is effectively a "left" variant of the existing [`file_stem`](https://doc.rust-lang.org/std/path/struct.Path.html#method.file_stem) method. An illustration of the difference is ```rust use std::path::Path; let path = Path::new("foo.tar.gz"); assert_eq!(path.file_stem(), Some("foo.tar")); assert_eq!(path.file_prefix(), Some("foo")); ``` In my own development, I generally find I almost always want the prefix, rather than the stem, so I thought it might be best to suggest it's addition to libstd. Of course, as this is my first contribution, I expect there is probably more work that needs to be done. Additionally, if the libstd team feel this isn't appropriate then so be it. There has been some [discussion about this on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/file_lstem/near/238076313) and a user there suggested I open a PR to see whether someone in the libstd team thinks it is worth pursuing.
2021-08-20Auto merge of #86898 - the8472:path-cmp, r=dtolnaybors-7/+40
Add fast path for Path::cmp that skips over long shared prefixes ``` # before test path::tests::bench_path_cmp_fast_path_buf_sort ... bench: 60,811 ns/iter (+/- 865) test path::tests::bench_path_cmp_fast_path_long ... bench: 6,459 ns/iter (+/- 275) test path::tests::bench_path_cmp_fast_path_short ... bench: 1,777 ns/iter (+/- 34) # after test path::tests::bench_path_cmp_fast_path_buf_sort ... bench: 38,140 ns/iter (+/- 211) test path::tests::bench_path_cmp_fast_path_long ... bench: 1,471 ns/iter (+/- 24) test path::tests::bench_path_cmp_fast_path_short ... bench: 1,106 ns/iter (+/- 9) ```
2021-08-17remove unnecessary empty checkMichael Hall-3/+1
2021-08-08Bump shrink_to stabilization to Rust 1.56David Tolnay-1/+1
2021-07-06optimize {Path,PathBuf,Components}::{cmp,partial_cmp} for shared prefixesThe8472-6/+39
2021-07-06Stabilize Vec<T>::shrink_toYoh Deadfall-1/+1
2021-07-06use Eq::eq instead of Iterator::eq implementationThe8472-1/+1
2021-06-24make docs clearer about how hidden files are dealt withMichael Hall-5/+19
2021-06-24change return signature for split_file_at_dotMichael Hall-6/+8
2021-06-18Auto merge of #85747 - maxwase:path-symlinks-methods, r=m-ou-sebors-0/+26
Path methods — symlinks improvement This PR adds symlink method for the `Path`. Tracking issue: #85748 For the discussion you can see [internals topic](https://internals.rust-lang.org/t/path-methods-symlinks-improvement/14776) P.S. I'm not fully sure about `stable` attribute, correct me if I'm wrong.
2021-06-18`no_run` and `ignore` doc attributesMax Wase-1/+2
2021-06-15simplify logic for split_file_at_dotMichael Hall-8/+4
2021-06-09optimize Eq implementation for pathsThe8472-1/+1
Filesystems generally have a tree-ish structure which means paths are more likely to share a prefix than a suffix. Absolute paths are especially prone to share long prefixes.
2021-06-06Update doc library/std/src/path.rsMax Wase-1/+0
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>