crosvm/sys_util/src/raw_fd.rs
Miriam Zimmerman 3a794ccb25 Add "Fd" wrapper for RawFd type.
This allows more type-safe usage of RawFds (preventing confusion with other c_ints) and provides a lightweight type that is usable in arguments to methods that take parameters of type AsRawFd.

BUG=None
TEST=Built.

Change-Id: Ibdeb03b0e759577385b05acb25ce76d51f2188c6
Reviewed-on: https://chromium-review.googlesource.com/1396495
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Miriam Zimmerman <mutexlox@chromium.org>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-01-05 20:08:32 -08:00

16 lines
531 B
Rust

// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Utility file to provide a slightly safer Fd type that cannot be confused with c_int.
// Also useful for situations that require something that is `AsRawFd` but
// where we don't want to store more than the fd.
use std::os::unix::io::{AsRawFd, RawFd};
pub struct Fd(pub RawFd);
impl AsRawFd for Fd {
fn as_raw_fd(&self) -> RawFd {
self.0
}
}