pub struct OwnedFd { /* private fields */ }
Expand description
OwnedFd is an RAII wrapper around RawFd: it automatically closes on drop & provides borrow() functionality to support lifetimes & borrow checking around the use of file descriptors
Compared to using File, TcpStream, etc as a wrapper to close on drop, OwnedFd:
- allows any type of filedescriptor to be used safely
- has no overhead greater than a RawFd (no buffer, metadata, or other allocations)
- allows use of the borrow system to ensure drop (close) happens only when all users of an ownedfd have released it.
Implementations§
Source§impl OwnedFd
impl OwnedFd
Sourcepub unsafe fn from_unowned_raw(i: RawFd) -> Result<OwnedFd>
pub unsafe fn from_unowned_raw(i: RawFd) -> Result<OwnedFd>
Given a raw file descriptor that may be owned by another (ie: another data structure might close it), create a Owned version that we have control over (via dup())
For taking ownership, see FromRawFd::from_raw_fd()
.
Unsafety:
- @i must be a valid file descriptor (of any kind)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OwnedFd
impl RefUnwindSafe for OwnedFd
impl Send for OwnedFd
impl Sync for OwnedFd
impl Unpin for OwnedFd
impl UnwindSafe for OwnedFd
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)