1 // c_str!() from the byte-strings crate is implemented via a proc macro which seems a bit excessive
4 #![allow(unused_unsafe)]
5 let bytes
= concat
!($data
, "\0");
6 unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked(bytes.as_bytes()) }
10 macro_rules
! file_descriptor_type
{
13 pub struct $
type(::std
::os
::unix
::io
::RawFd
);
15 file_descriptor_impl
!($
type);
17 impl ::std
::os
::unix
::io
::FromRawFd
for $
type {
18 unsafe fn from_raw_fd(fd
: ::std
::os
::unix
::io
::RawFd
) -> Self {
25 macro_rules
! file_descriptor_impl
{
37 impl ::std
::os
::unix
::io
::AsFd
for $
type {
38 fn as_fd(&self) -> ::std
::os
::unix
::io
::BorrowedFd
<'_
> {
39 unsafe { ::std::os::unix::io::BorrowedFd::borrow_raw(self.0) }
43 impl ::std
::os
::unix
::io
::AsRawFd
for $
type {
44 fn as_raw_fd(&self) -> ::std
::os
::unix
::io
::RawFd
{
49 impl ::std
::os
::unix
::io
::IntoRawFd
for $
type {
50 fn into_raw_fd(mut self) -> ::std
::os
::unix
::io
::RawFd
{
52 self.0 = -libc
::EBADF
;
59 macro_rules
! c_result
{
63 Err(::std
::io
::Error
::last_os_error())
65 Ok
::<_
, ::std
::io
::Error
>(res
)
76 macro_rules
! io_format_err
{
78 ::std
::io
::Error
::new(::std
::io
::ErrorKind
::Other
, format
!($
($msg
)*))
82 macro_rules
! io_bail
{
84 return Err(::std
::io
::Error
::new(::std
::io
::ErrorKind
::Other
, format
!($
($msg
)*)));