Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AsFd for &T and &mut T. #93888

Merged
merged 1 commit into from
Feb 12, 2022

Commits on Feb 11, 2022

  1. Implement AsFd for &T and &mut T.

    Add implementations of `AsFd` for `&T` and `&mut T`, so that users can
    write code like this:
    
    ```rust
    pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
    ```
    
    with `fd: F` rather than `fd: &F`.
    
    And similar for `AsHandle` and `AsSocket` on Windows.
    
    Also, adjust the `fchown` example to pass the file by reference. The
    code can work either way now, but passing by reference is more likely
    to be what users will want to do.
    
    This is an alternative to rust-lang#93869, and is a simpler way to achieve the
    same goals: users don't need to pass borrowed-`BorrowedFd` arguments,
    and it prevents a pitfall in the case where users write `fd: F` instead
    of `fd: &F`.
    sunfishcode committed Feb 11, 2022
    Configuration menu
    Copy the full SHA
    1f98ef7 View commit details
    Browse the repository at this point in the history