1. 06 7月, 2021 2 次提交
    • Y
      Rollup merge of #85377 - ijackson:abort-docs, r=m-ou-se · add24d2f
      Yuki Okushi 提交于
      aborts: Clarify documentation and comments
      
      In the docs for intrinsics::abort():
      
       * Strengthen the recommendation by to use process::abort instead.
       * Document the fact that it sometimes (ab)uses an LLVM debug trap and what the likely consequences are.
       * State that the precise behaviour is unstable.
      
      In the docs for process::abort():
      
       * Promise that we have the same behaviour as C `abort()`.
       * Document the likely consequences, including, specifically, the consequences on Unix.
      
      In the internal comment for unix::abort_internal:
      
       * Refer to the public docs for the public API functions.
       * Correct and expand the description of libc::abort.  Specifically:
       * Do not claim that abort() unregisters signal handlers.  It doesn't; it honours the SIGABRT handler.
       * Discuss, extensively, the issue with abort() flushing stdio buffers.
       * Describe the glibc behaviour in some detail.
      Co-authored-by: NMark Wooding <mdw@distorted.org.uk>
      Signed-off-by: NIan Jackson <ijackson@chiark.greenend.org.uk>
      
      Fixes #40230
      add24d2f
    • Y
      Rollup merge of #83581 - arennow:dir_entry_ext_unix_borrow_name, r=m-ou-se · 1fcd9abb
      Yuki Okushi 提交于
      Add std::os::unix::fs::DirEntryExt2::file_name_ref(&self) -> &OsStr
      
      Greetings!
      
      This is my first PR here, so please forgive me if I've missed an important step or otherwise done something wrong. I'm very open to suggestions/fixes/corrections.
      
      This PR adds a function that allows `std::fs::DirEntry` to vend a borrow of its filename on Unix platforms, which is especially useful for sorting. (Windows has (as I understand it) encoding differences that require an allocation.) This new function sits alongside the cross-platform [`file_name(&self) -> OsString`](https://doc.rust-lang.org/std/fs/struct.DirEntry.html#method.file_name) function.
      
      I pitched this idea in an [internals thread](https://internals.rust-lang.org/t/allow-std-direntry-to-vend-borrows-of-its-filename/14328/4), and no one objected vehemently, so here we are.
      
      I understand features in general, I believe, but I'm not at all confident that my whole-cloth invention of a new feature string (as required by the compiler) was correct (or that the name is appropriate). Further, there doesn't appear to be a test for the sibling `ino` function, so I didn't add one for this similarly trivial function either. If it's desirable that I should do so, I'd be happy to [figure out how to] do that.
      
      The following is a trivial sample of a use-case for this function, in which directory entries are sorted without any additional allocations:
      
      ```rust
      use std::os::unix::fs::DirEntryExt;
      use std::{fs, io};
      
      fn main() -> io::Result<()> {
          let mut entries = fs::read_dir(".")?.collect::<Result<Vec<_>, io::Error>>()?;
          entries.sort_unstable_by(|a, b| a.file_name_ref().cmp(b.file_name_ref()));
      
          for p in entries {
              println!("{:?}", p);
          }
      
          Ok(())
      }
      ```
      1fcd9abb
  2. 05 7月, 2021 34 次提交
  3. 04 7月, 2021 4 次提交