Commit Graph

34 Commits

Author SHA1 Message Date
Josh Stone f854070bb8 Forward OsStr::clone_into to the inner Vec
Despite OS differences, they're all just `Vec<u8>` inside, so we can
just forward `clone_into` calls to that optimized implementation.
2020-04-06 18:26:37 -07:00
Dylan DPC d584f5a386
Rollup merge of #69937 - TyPR124:osstr_ascii, r=dtolnay
ASCII methods on OsStr

Would close #69566

I don't know enough about encodings to know if this is a valid change, however the comment on the issue suggests it could be.

This does two things:

1. Makes ASCII methods available on OsStr

2. Makes it possible to obtain a `&mut OsStr`. This is necessary to actually use `OsStr::make_ascii_*case` methods since they modify the underlying value. As far as I can tell, the only way to modify a `&mut OsStr` is via the methods I just added.

My original hope was to have these methods on `OsStrExt` for Windows, since the standard library already assumes `make_ascii_uppercase` is valid in Windows (see the change I made to windows/process.rs). If it is found these are not valid changes on non-Windows platforms, I can move the methods to the ext trait instead.
2020-03-29 01:32:17 +01:00
TyPR124 cc584d5166 ascii methods on osstr 2020-03-28 18:34:48 -04:00
lzutao e1bc9af9eb
Fix wrong deref 2020-03-16 23:54:32 +07:00
lzutao ce5e49f86f
Use sublice patterns to avoid computing the len 2020-03-16 23:43:42 +07:00
Matthias Krüger 8351138370 reduce references on match patterns (clippy::match_ref_pats) 2020-03-07 21:48:17 +01:00
David Tolnay 4436c9d354
Format libstd with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd *that are not involved in any currently open PR* to
minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8

With the list of files from the script in outstanding_files, the
relevant commands were:

    $ find src/libstd -name '*.rs' \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ rg libstd outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of
most of the rest of libstd.

To confirm no funny business:

    $ git checkout $THIS_COMMIT^
    $ git show --pretty= --name-only $THIS_COMMIT \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ git diff $THIS_COMMIT  # there should be no difference
2019-11-29 18:43:27 -08:00
Matthias Geier be12ab070d Use "capacity" as parameter name in with_capacity() methods
Closes #60271.
2019-04-26 18:43:24 +02:00
Josh Stone 0730a01c5c Use for_each to extend collections
This updates the `Extend` implementations to use `for_each` for many
collections: `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `Path`,
`TokenStream`, `VecDeque`, and `Wtf8Buf`.

Folding with `for_each` enables better performance than a `for`-loop for
some iterators, especially if they can just forward to internal
iterators, like `Chain` and `FlatMap` do.
2019-04-05 14:51:07 -07:00
Mazdak Farrokhzad 379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
Taiki Endo 93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
Alexander Regueiro 99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
ljedrz 8c4129cd9a cleanup: remove static lifetimes from consts in libstd 2018-12-04 10:21:42 +01:00
teresy eca11b99a7 refactor: use shorthand fields 2018-11-06 15:05:44 -05:00
Corey Farwell 993fb93464 Replace usages of ptr::offset with ptr::{add,sub}. 2018-08-20 07:28:34 -04:00
ljedrz 57a5a9b054 Prefer to_string() to format!() 2018-07-27 11:11:18 +02:00
Zack M. Davis 057715557b migrate codebase to `..=` inclusive range patterns
These were stabilized in March 2018's #47813, and are the Preferred Way
to Do It going forward (q.v. #51043).
2018-06-26 07:53:30 -07:00
Andre Bogus e333725664 use fmt::Result where applicable 2018-05-09 02:01:37 +02:00
Simon Sapin 572256772e Remove unused methods on the private Wtf8 type
The type and its direct parent module are `pub`, but they’re not reachable outside of std
2018-04-21 09:45:18 +02:00
Diggory Blake 04f6692aaf Implement `shrink_to` method on collections 2018-03-27 01:39:11 +01:00
Simon Sapin c09b9f9372 Deprecate the AsciiExt trait in favor of inherent methods
The trait and some of its methods are stable and will remain.
Some of the newer methods are unstable and can be removed later.

Fixes https://github.com/rust-lang/rust/issues/39658
2018-03-21 17:54:33 +01:00
leonardo.yvens 2e7e68b762 while let all the things 2018-03-05 15:58:54 -03:00
Diggory Blake ccc91d7b48 Capture environment at spawn 2017-12-24 14:24:31 +00:00
Matt Brubeck 3024c1434a Use Try syntax for Option in place of macros or match 2017-12-09 14:18:33 -08:00
Murarth 1bbc776446 Implement `Rc`/`Arc` conversions for string-like types
Provides the following conversion implementations:

* `From<`{`CString`,`&CStr`}`>` for {`Arc`,`Rc`}`<CStr>`
* `From<`{`OsString`,`&OsStr`}`>` for {`Arc`,`Rc`}`<OsStr>`
* `From<`{`PathBuf`,`&Path`}`>` for {`Arc`,`Rc`}`<Path>`
2017-11-25 22:13:11 -07:00
Alex Crichton 742ca0caf2 std: Respect formatting flags for str-like OsStr
Historically many `Display` and `Debug` implementations for `OsStr`-like
abstractions have gone through `String::from_utf8_lossy`, but this was updated
in #42613 to use an internal `Utf8Lossy` abstraction instead. This had the
unfortunate side effect of causing a regression (#43765) in code which relied on
these `fmt` trait implementations respecting the various formatting flags
specified.

This commit opportunistically adds back interpretation of formatting trait flags
in the "common case" where where `OsStr`-like "thing" is all valid utf-8 and can
delegate to the formatting implementation for `str`. This doesn't entirely solve
the regression as non-utf8 paths will format differently than they did before
still (in that they will not respect formatting flags), but this should solve
the regression for all "real world" use cases of paths and such. The door's also
still open for handling these flags in the future!

Closes #43765
2017-08-13 21:07:03 -07:00
Stepan Koltsov ac96fd7787 Avoid allocations in Debug for os_str
Fixes #38879
2017-06-15 20:42:37 +01:00
David LeGare db16ca7c83 Update documention in windows::ffi 2017-05-05 20:35:07 -05:00
bors 71d7b29475 Auto merge of #40009 - clarcharr:box_to_buf, r=alexcrichton
Leftovers from #39594; From<Box> impls

These are a few more impls that follow the same reasoning as those from #39594.

What's included:
* `From<Box<str>> for String`
* `From<Box<[T]>> for Vec<T>`
* `From<Box<CStr>> for CString`
* `From<Box<OsStr>> for OsString`
* `From<Box<Path>> for PathBuf`
* `Into<Box<str>> for String`
* `Into<Box<[T]>> for Vec<T>`
* `Into<Box<CStr>> for CString`
* `Into<Box<OsStr>> for OsString`
* `Into<Box<Path>> for PathBuf`
* `<Box<CStr>>::into_c_string`
* `<Box<OsStr>>::into_os_string`
* `<Box<Path>>::into_path_buf`
* Tracking issue for latter three methods + three from previous PR.

Currently, the opposite direction isn't doable with `From` (only `Into`) because of the separation between `liballoc` and `libcollections`. I'm holding off on those for a later PR.
2017-03-15 04:24:10 +00:00
Clar Charr 560944b982 Add From<Box<..>> implementations. 2017-03-10 14:57:57 -05:00
Clar Charr 83814fd8ab OsString::shrink_to_fit. 2017-03-10 12:15:30 -05:00
Clar Charr 963843b1b3 Conversions between CStr/OsStr/Path and boxes. 2017-02-14 14:18:43 -05:00
Brian Anderson ca30691813 std: Move sys_common to libstd/sys_common
Make the directory structure reflect the module structure. I've always
found the existing structure confusing.
2016-11-01 17:08:24 +00:00