about summary refs log tree commit diff
path: root/library/std/src/ffi
AgeCommit message (Collapse)AuthorLines
2024-03-10Rollup merge of #112136 - clarfonthey:ffi-c_str, r=cuviperMatthias Krüger-6/+45
Add std::ffi::c_str module ACP: rust-lang/libs-team#134 `std::ffi` docs before change: ![Structs: VaList, VaListImpl, CStr, CString, FromBytesWithNulError, FromVecWithNulError, IntoStringError, NulError, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/b2cf3534-30f9-4ef0-a655-bacdc3a19e17) `std::ffi` docs after change: ![Re-exports: self::c_str::{FromBytesWithNulError, FromBytesUntilNulError, FromVecWithNulError, NulError, IntoStringError} ; Modules: c_str ; Structs: VaList, VaListImpl, CStr, CString, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/23aa6964-da7a-4942-bbf7-42bde2146f9e) (note: I'm omitting the `c_int`, etc. stuff from the screenshots since it's the same in both. this doesn't just delete those types)
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-03-07Rust is a proper name: rust → RustRalf Jung-4/+4
2024-02-28Rollup merge of #120051 - riverbl:os-str-display, r=m-ou-seGuillaume Gomez-4/+67
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-02-22Add std::ffi::c_str modulesltdk-6/+45
2024-01-21Move `OsStr::slice_encoded_bytes` validation to platform modulesJan Verbeek-42/+76
On Windows and UEFI this improves performance and error messaging. On other platforms we optimize the fast path a bit more. This also prepares for later relaxing the checks on certain platforms.
2024-01-18Add `display` method to `OsStr`riverbl-4/+67
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-12-10remove redundant importssurechen-4/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-02Add substring API for `OsStr`Jan Verbeek-2/+130
2023-10-03Bump version placeholdersMark Rousskov-4/+4
2023-09-01fix(std): Rename os_str_bytes to encoded_bytesEd Page-30/+30
2023-09-01feat(std): Stabilize 'os_str_bytes' featureEd Page-8/+4
Closes #111544
2023-08-22Replace version placeholders with 1.73.0Mark Rousskov-1/+1
2023-08-14actually this doesn't even affect doctests. nice.Ralf Jung-6/+3
2023-08-14std: add some missing repr(transparent)Ralf Jung-0/+3
2023-07-31Rollup merge of #113701 - aswild:std-ffi-frombytesuntilnul, r=dtolnayMatthias Krüger-0/+2
Re-export core::ffi::FromBytesUntilNulError in std::ffi Like the other CStr and CString error types, make a re-export for std::ffi::FromBytesUntilNulError. This seems to have slipped through the cracks in the cstr_from_bytes_until_nul implementation and core_c_str migration. Tracking Issue: #95027
2023-07-22Rollup merge of #113442 - epage:osstring, r=cuviperMatthias Krüger-0/+65
Allow limited access to `OsString` bytes This extends #109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in #111544.
2023-07-14Re-export core::ffi::FromBytesUntilNulError in std::ffiAllen Wild-0/+2
Like the other CStr and CString error types, make a re-export for std::ffi::FromBytesUntilNulError. This seems to have slipped through the cracks in the cstr_from_bytes_until_nul implementation and core_c_str migration. Tracking Issue: #95027
2023-07-12Replace version placeholder to 1.72Mark Rousskov-1/+1
2023-07-07Allow limited access to `OsString` bytesEd Page-0/+65
This extends #109698 to allow no-cost conversion between `Vec<u8>` and `OsString` as suggested in feedback from `os_str_bytes` crate in #111544.
2023-06-14Rollup merge of #98202 - aticu:impl_tryfrom_osstr_for_str, r=AmanieuMatthias Krüger-1/+19
Implement `TryFrom<&OsStr>` for `&str` Recently when trying to work with `&OsStr` I was surprised to find this `impl` missing. Since the `to_str` method already existed the actual implementation is fairly non-controversial, except for maybe the choice of the error type. I chose an opaque error here instead of something like `std::str::Utf8Error`, since that would already make a number of assumption about the underlying implementation of `OsStr`. As this is a trait implementation, it is insta-stable, if I'm not mistaken? Either way this will need an FCP. I chose "1.64.0" as the version, since this is unlikely to land before the beta cut-off. `@rustbot` modify labels: +T-libs-api API Change Proposal: rust-lang/rust#99031 (accepted)
2023-06-12Implement `TryFrom<&OsStr>` for `&str`aticu-1/+19
2023-05-19docs: Add missing periodEd Page-1/+1
2023-05-17docs: Clarify OsStr is self-synchronizingEd Page-7/+15
2023-05-16docs: Add examples of OsStr safety violationEd Page-4/+7
2023-05-13refactor: Remove redundant, private OsStr::bytesEd Page-18/+9
2023-03-27Allow access to `OsStr` bytesEd Page-1/+63
`OsStr` has historically kept its implementation details private out of concern for locking us into a specific encoding on Windows. This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines rules for safely interacting with it At minimum, this can greatly simplify the `os_str_bytes` crate and every arg parser that interacts with `OsStr` directly (which is most of those that support invalid UTF-8).
2023-04-12remove some unneeded importsKaDiWa-1/+0
2022-08-10Guarantee `try_reserve` preserves the contents on errorYOSHIOKA Takuma-1/+2
Update doc comments to make the guarantee explicit. However, some implementations does not have the statement though. * `HashMap`, `HashSet`: require guarantees on hashbrown side. * `PathBuf`: simply redirecting to `OsString`. Fixes #99606.
2022-07-17Rollup merge of #97915 - tbu-:pr_os_string_fmt_write, r=joshtriplettYuki Okushi-0/+8
Implement `fmt::Write` for `OsString` This allows to format into an `OsString` without unnecessary allocations. E.g. ``` let mut temp_filename = path.into_os_string(); write!(&mut temp_filename, ".tmp.{}", process::id()); ```
2022-07-16Update `since` version to 1.64Josh Triplett-1/+1
2022-07-15Stabilize `core::ffi::CStr`, `alloc::ffi::CString`, and friendsJosh Triplett-18/+4
Stabilize the `core_c_str` and `alloc_c_string` feature gates. Change `std::ffi` to re-export these types rather than creating type aliases, since they now have matching stability.
2022-07-14Rollup merge of #98315 - joshtriplett:stabilize-core-ffi-c, r=Mark-SimulacrumDylan DPC-0/+6
Stabilize `core::ffi:c_*` and rexport in `std::ffi` This only stabilizes the base types, not the non-zero variants, since those have their own separate tracking issue and have not gone through FCP to stabilize.
2022-07-13Stabilize `core::ffi:c_*` and rexport in `std::ffi`Josh Triplett-0/+6
This only stabilizes the base types, not the non-zero variants, since those have their own separate tracking issue and have not gone through FCP to stabilize.
2022-06-19Fix documentation for with_capacity and reserve families of methodsjmaargh-10/+12
Documentation for the following methods with_capacity with_capacity_in with_capacity_and_hasher reserve reserve_exact try_reserve try_reserve_exact was inconsistent and often not entirely correct where they existed on the following types Vec VecDeque String OsString PathBuf BinaryHeap HashSet HashMap BufWriter LineWriter since the allocator is allowed to allocate more than the requested capacity in all such cases, and will frequently "allocate" much more in the case of zero-sized types (I also checked BufReader, but there the docs appear to be accurate as it appears to actually allocate the exact capacity). Some effort was made to make the documentation more consistent between types as well. Fix with_capacity* methods for Vec Fix *reserve* methods for Vec Fix docs for *reserve* methods of VecDeque Fix docs for String::with_capacity Fix docs for *reserve* methods of String Fix docs for OsString::with_capacity Fix docs for *reserve* methods on OsString Fix docs for with_capacity* methods on HashSet Fix docs for *reserve methods of HashSet Fix docs for with_capacity* methods of HashMap Fix docs for *reserve methods on HashMap Fix expect messages about OOM in doctests Fix docs for BinaryHeap::with_capacity Fix docs for *reserve* methods of BinaryHeap Fix typos Fix docs for with_capacity on BufWriter and LineWriter Fix consistent use of `hasher` between `HashMap` and `HashSet` Fix warning in doc test Add test for capacity of vec with ZST Fix doc test error
2022-06-17Rollup merge of #95392 - Xuanwo:stablize_try_reserve_2, r=dtolnayDylan DPC-4/+2
std: Stabilize feature try_reserve_2 This PR intends to stabilize feature `try_reserve_2`, closes https://github.com/rust-lang/rust/issues/91789 This PR will also replace the previous PR: https://github.com/rust-lang/rust/pull/95139
2022-06-16std: Stabilize feature try_reserve_2Xuanwo-4/+2
Signed-off-by: Xuanwo <github@xuanwo.io>
2022-06-16Rollup merge of #97202 - joshtriplett:os-str-capacity-documentation, r=dtolnayYuki Okushi-2/+32
os str capacity documentation This is based on https://github.com/rust-lang/rust/pull/95394 , with expansion and consolidation to address comments from `@dtolnay` and other `@rust-lang/libs-api` team members.
2022-06-09Implement `fmt::Write` for `OsString`Tobias Bucher-0/+8
This allows to format into an `OsString` without unnecessary allocations. E.g. ``` let mut temp_filename = path.into_os_string(); write!(&mut temp_filename, ".tmp.{}", process::id()); ```
2022-05-31Auto merge of #96881 - est31:join_osstr, r=dtolnaybors-0/+31
Implement [OsStr]::join Implements join for `OsStr` and `OsString` slices: ```Rust let strings = [OsStr::new("hello"), OsStr::new("dear"), OsStr::new("world")]; assert_eq!("hello dear world", strings.join(OsStr::new(" "))); ```` This saves one from converting to strings and back, or from implementing it manually. This PR has been re-filed after #96744 was first accidentally merged and then reverted. The change is instantly stable and thus: r? rust-lang/libs-api `@rustbot` label +T-libs-api -T-libs cc `@thomcc` `@m-ou-se` `@faptc`
2022-05-27docs: Don't imply that OsStr on Unix is always UTF-8Xiretza-1/+1
The methods in `OsStrExt` consume and return `&[u8]` and don't perform any UTF-8 checks.
2022-05-21Expand the explanation of OsString capacityJosh Triplett-3/+14
2022-05-19OsString: Consolidate all documentation about capacity in top-level docsJosh Triplett-28/+12
2022-05-18std: Add capacity guarantees notes for OsStringXuanwo-0/+35
Signed-off-by: Xuanwo <github@xuanwo.io>
2022-05-11Rollup merge of #96861 - m-ou-se:std-use-prelude-2021, r=joshtriplettYuki Okushi-1/+1
Use Rust 2021 prelude in std itself.
2022-05-09Implement [OsStr]::joinest31-0/+31
Second attempt at implementing [OsStr]::join.
2022-05-09Use Rust 2021 prelude in std itself.Mara Bos-1/+1
2022-05-08Revert "Implement [OsStr]::join", which was merged without FCPThom Chiovoloni-31/+0
This reverts commit 4fcbc53820ab423bbeb41f07822369aa05da1d68.
2022-05-05Implement [OsStr]::joinest31-0/+31