about summary refs log tree commit diff
path: root/library/std/src/ffi
AgeCommit message (Collapse)AuthorLines
2021-10-11Rollup merge of #89753 - jkugelman:must-use-from_value-conversions, ↵Guillaume Gomez-0/+5
r=joshtriplett Add #[must_use] to from_value conversions I added two methods to the list myself. Clippy did not flag them because they take `mut` args, but neither modifies their argument. ```rust core::str const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str; std::ffi::CString unsafe fn from_raw(ptr: *mut c_char) -> CString; ``` I put a custom note on `from_raw`: ```rust #[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"] pub unsafe fn from_raw(ptr: *mut c_char) -> CString { ``` Parent issue: #89692 r? ``@joshtriplett``
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-1/+8
2021-10-10Add #[must_use] to from_value conversionsJohn Kugelman-0/+5
2021-10-10Add #[must_use] to core and std constructorsJohn Kugelman-0/+2
2021-10-09Add #[must_use] to string/char transformation methodsJohn Kugelman-0/+2
These methods could be misconstrued as modifying their arguments instead of returning new values. Where possible I made the note recommend a method that does mutate in place.
2021-09-28Clarify that `CString::from_vec_unchecked` appends 0 byte.et342-0/+2
2021-09-25Rollup merge of #89216 - r00ster91:bigo, r=dtolnayManish Goregaokar-2/+2
Consistent big O notation This makes the big O time complexity notation in places with markdown support more consistent. Inspired by #89210
2021-09-25Auto merge of #88343 - steffahn:fix_code_spacing, r=jyn514bors-78/+70
Fix spacing of links in inline code. Similar to #80733, but the focus is different. This PR eliminates all occurrences of pieced-together inline code blocks like [`Box`]`<`[`Option`]`<T>>` and replaces them with good-looking ones (using HTML-syntax), like <code>[Box]<[Option]\<T>></code>. As far as I can tell, I should’ve found all of these in the standard library (regex search with `` r"`\]`|`\[`" ``) \[except for in `core::convert` where I’ve noticed other things in the docs that I want to fix in a separate PR]. In particular, unlike #80733, I’ve added almost no new instance of inline code that’s broken up into multiple links (or some link and some link-free part). I also added tooltips (the stuff in quotes for the markdown link listings) in places that caught my eye, but that’s by no means systematic, just opportunistic. [Box]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box" [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box" [Option]: https://doc.rust-lang.org/std/option/enum.Option.html "Option" [`Option`]: https://doc.rust-lang.org/std/option/enum.Option.html "Option" Context: I got annoyed by repeatedly running into new misformatted inline code while reading the standard library docs. I know that once issue #83997 (and/or related ones) are resolved, these changes become somewhat obsolete, but I fail to notice much progress on that end right now. r? `@jyn514`
2021-09-25Apply 16 commits (squashed)Frank Steffahn-78/+70
---------- 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-09-24consistent big O notationr00ster91-2/+2
2021-09-15docs(std): add docs for cof_from_cstr implsMichael Howell-0/+3
CC #51430
2021-08-24Fix typo “a Rc” → “an Rc”Frank Steffahn-2/+2
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-22Fix more “a”/“an” typosFrank Steffahn-2/+2
2021-08-22Fix typos “a”→“an”Frank Steffahn-6/+6
2021-08-08Auto merge of #86879 - YohDeadfall:stabilize-vec-shrink-to, r=dtolnaybors-2/+1
Stabilize Vec<T>::shrink_to This PR stabilizes `shrink_to` feature and closes the corresponding issue. The second point was addressed already, and no `panic!` should occur. Closes #56431.
2021-08-08Bump shrink_to stabilization to Rust 1.56David Tolnay-1/+1
2021-08-05alloc: Use intra doc links for the reserve functionest31-1/+3
The sentence exists to highlight the existence of a performance footgun of repeated calls of the reserve_exact function.
2021-07-06Stabilize Vec<T>::shrink_toYoh Deadfall-2/+1
2021-06-30Remove "length" doc aliasesAmanieu d'Antras-1/+0
2021-06-23Use HTTPS links where possibleSmitty-2/+2
2021-05-26Add inline attr to private CString::into_innerElichai Turkel-0/+1
2021-05-20Rollup merge of #85275 - CDirkx:memchr, r=m-ou-seGuillaume Gomez-1/+1
Move `std::memchr` to `sys_common` `std::memchr` is a thin abstraction over the different `memchr` implementations in `sys`, along with documentation and tests. The module is only used internally by `std`, nothing is exported externally. Code like this is exactly what the `sys_common` module is for, so this PR moves it there.
2021-05-18Add diagnostic item to `CStr`Mateusz Gacek-0/+1
2021-05-17Simplify `cfg(any(unix, target_os="redox"))` to just `cfg(unix)`Christiaan Dirkx-1/+1
2021-05-14Move `std::memchr` to `sys_common`Christiaan Dirkx-1/+1
2021-05-02Change 'NULL' to 'null'Brent Kerby-1/+1
2021-04-27Override `clone_from` method for PathBuf and OsStringBenoît du Garreau-1/+13
2021-03-31Add a few missing links, fix a typoFrank Steffahn-1/+1
2021-03-31Fix documentation of conversion from String to OsStringFrank Steffahn-1/+1
2021-03-29ffi::c_str smaller as_bytesklensy-2/+4
2021-03-28ffi::c_str added tests for empty stringsklensy-0/+16
2021-03-24Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisaDylan DPC-1/+1
Add internal io::Error::new_const to avoid allocations. This makes it possible to have a io::Error containing a message with zero allocations, and uses that everywhere to avoid the *three* allocations involved in `io::Error::new(kind, "message")`. The function signature isn't perfect, because it needs a reference to the `&str`. So for now, this is just a `pub(crate)` function. Later, we'll be able to use `fn new_const<MSG: &'static str>(kind: ErrorKind)` to make that a bit better. (Then we'll also be able to use some ZST trickery if that would result in more efficient code.) See https://github.com/rust-lang/rust/issues/83352
2021-03-22Rollup merge of #80193 - zseri:stabilize-osstring-ascii, r=m-ou-seDylan DPC-12/+6
stabilize `feature(osstring_ascii)` This PR stabilizes `feature(osstring_ascii)`. Fixes #70516.
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-1/+1
2021-03-21Bump osstring_ascii stabilization version to 1.53.0.Mara Bos-6/+6
2021-03-14Rollup merge of #82121 - lopopolo:pathbuf-osstring-extend, r=joshtriplettYuki Okushi-0/+86
Implement Extend and FromIterator for OsString Add the following trait impls: - `impl Extend<OsString> for OsString` - `impl<'a> Extend<&'a OsStr> for OsString` - `impl FromIterator<OsString> for OsString` - `impl<'a> FromIterator<&'a OsStr> for OsString` Because `OsString` is a platform string with no particular semantics, concatenating them together seems acceptable. I came across a use case for these trait impls in https://github.com/artichoke/artichoke/pull/1089: Artichoke is a Ruby interpreter. Its CLI accepts multiple `-e` switches for executing inline Ruby code, like: ```console $ cargo -q run --bin artichoke -- -e '2.times {' -e 'puts "foo: #{__LINE__}"' -e '}' foo: 2 foo: 2 ``` I use `clap` for command line argument parsing, which collects these `-e` commands into a `Vec<OsString>`. To pass these commands to the interpreter for `Eval`, I need to join them together. Combining these impls with `Iterator::intersperse` https://github.com/rust-lang/rust/issues/79524 would enable me to build a single bit of Ruby code. Currently, I'm doing something like: ```rust let mut commands = commands.into_iter(); let mut buf = if let Some(command) = commands.next() { command } else { return Ok(Ok(())); }; for command in commands { buf.push("\n"); buf.push(command); } ``` If there's interest, I'd also like to add impls for `Cow<'a, OsStr>`, which would avoid allocating the `"\n"` `OsString` in the concatenate + intersperse use case.
2021-03-05stabilize feature(osstring_ascii)zseri-12/+6
2021-03-03Add impls for iterators of Cow<OsStr>Ryan Lopopolo-0/+34
2021-02-25Convert primitives to use intra-doc linksJoshua Nelson-4/+2
2021-02-23Rollup merge of #82128 - anall:feature/add_diagnostic_items, r=davidtwcoDylan DPC-0/+2
add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice This is adding diagnostic items to be used by rust-lang/rust-clippy#6730, but my understanding is the clippy-side change does need to be done over there since I am adding a new clippy feature. Add diagnostic items to the following types: OsString (os_string_type) PathBuf (path_buf_type) Owned (to_owned_trait) As well as the to_vec method on slice/[T]
2021-02-16Optimize FromIterator<OsString> to reuse the first allocationRyan Lopopolo-4/+11
2021-02-16a few more diagnostic itemsAndrea Nall-0/+1
2021-02-15requested/proposed changesAndrea Nall-1/+1
2021-02-15add diagnostic itemsAndrea Nall-0/+1
Add diagnostic items to the following types: OsString (os_string_type) PathBuf (path_buf_type) Owned (to_owned_trait) As well as the to_vec method on slice/[T]
2021-02-14Implement Extend and FromIterator for OsStringRyan Lopopolo-0/+45
Add the following trait impls: - `impl Extend<OsString> for OsString` - `impl<'a> Extend<&'a OsStr> for OsString` - `impl FromIterator<OsString> for OsString` - `impl<'a> FromIterator<&'a OsStr> for OsString` Because `OsString` is a platform string with no particular semantics, concatenating them together seems acceptable.
2021-02-10Seal the CommandExt, OsStrExt and OsStringExt traitsAmanieu d'Antras-0/+8
2021-02-03OsStr eq_ignore_ascii_case takes arg by valueTyler Ruckinger-1/+1
Per a comment on #70516 this changes `eq_ignore_ascii_case` to take the generic parameter `S: AsRef<OsStr>` by value instead of by reference. This is technically a breaking change to an unstable method. I think the only way it would break is if you called this method with an explicit type parameter, ie `my_os_str.eq_ignore_ascii_case::<str>("foo")` becomes `my_os_str.eq_ignore_ascii_case::<&str>("foo")`. Besides that, I believe it is overall more flexible since it can now take an owned `OsString` for example. If this change should be made in some other PR (like #80193) then please just close this.
2021-01-26shrink_to shouldn't panic on len greater than capacityThom Wiggers-2/+1