From f565f02731f93c894524aed602778b5f6e5fe022 Mon Sep 17 00:00:00 2001 From: crumblingstatue Date: Thu, 1 May 2025 16:23:46 +0200 Subject: [PATCH] Implement AsRawFd for &Pty Some APIs, like `nonblock::NonBlockingReader::from_fd` take a value that implements AsRawFd. Pty implements AsRawFd, but if we pass it by value, it will get moved, as it doesn't implement Clone or Copy. With this change, &Pty can now be passed without moving the Pty. --- src/blocking/pty.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/blocking/pty.rs b/src/blocking/pty.rs index 5436854..3f6f483 100644 --- a/src/blocking/pty.rs +++ b/src/blocking/pty.rs @@ -48,6 +48,12 @@ impl std::os::fd::AsRawFd for Pty { } } +impl std::os::fd::AsRawFd for &Pty { + fn as_raw_fd(&self) -> std::os::fd::RawFd { + self.0.as_raw_fd() + } +} + impl std::io::Read for Pty { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { self.0.read(buf)