1

Implement `AsFd` for `&T` and `&mut T`. by sunfishcode · Pull Request #9...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/93888
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Member

sunfishcode commented 6 days ago

Add implementations of AsFd for &T and &mut T, so that users can
write code like this:

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 #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.

r? @joshtriplett


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK