Skip to content

Commit

Permalink
Add repr(transparent) to the newtypes.
Browse files Browse the repository at this point in the history
This comes from the suggestion [here].

[here]: rust-lang/rust#76969 (comment)
  • Loading branch information
sunfishcode committed Feb 20, 2021
1 parent a84f5b8 commit bfdbab2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/unsafe_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ pub trait FromUnsafeSocket {
/// Note that this doesn't implement `Into*` or `From*` traits, as those imply
/// ownership transfers, and this type is non-owning.
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct UnsafeHandle(InnerFileOrSocket);

/// A non-owning unsafe I/O handle which on Windows is limited to handling what
Expand All @@ -358,6 +359,7 @@ pub struct UnsafeHandle(InnerFileOrSocket);
///
/// [`RawHandle`]: https://doc.rust-lang.org/std/os/windows/io/type.RawHandle.html
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct UnsafeFile(InnerFile);

/// A non-owning unsafe I/O handle which on Windows is limited to handling what
Expand All @@ -368,20 +370,23 @@ pub struct UnsafeFile(InnerFile);
///
/// [`RawSocket`]: https://doc.rust-lang.org/std/os/windows/io/type.RawSocket.html
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct UnsafeSocket(InnerSocket);

/// A non-owning unsafe I/O handle that implements [`Read`]. `Read` functions
/// are considered safe, so this type requires `unsafe` to construct.
///
/// Like [`UnsafeHandle`], this doesn't implement `Into*` or `From*` traits.
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct UnsafeReadable(InnerFileOrSocket);

/// A non-owning unsafe I/O handle that implements [`Write`]. `Write` functions
/// considered are safe, so this type requires `unsafe` to construct.
///
/// Like [`UnsafeHandle`], this doesn't implement `Into*` or `From*` traits.
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct UnsafeWriteable(InnerFileOrSocket);

/// Posix-ish platforms use a single "file descriptor" type for all the kinds
Expand Down

0 comments on commit bfdbab2

Please sign in to comment.