mirror of
https://github.com/wez/wezterm.git
synced 2024-09-11 14:25:57 +03:00
prep for publishing filedescriptor to crates.io
This commit is contained in:
parent
0d07c1e6b9
commit
a9fd318095
@ -3,6 +3,10 @@ name = "filedescriptor"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Wez Furlong"]
|
authors = ["Wez Furlong"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
repository = "https://github.com/wez/wzsh"
|
||||||
|
description = "More ergonomic wrappers around RawFd and RawHandle"
|
||||||
|
license = "MIT"
|
||||||
|
documentation = "https://docs.rs/filedescriptor"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
@ -15,4 +19,5 @@ winapi = { version = "0.3", features = [
|
|||||||
"handleapi",
|
"handleapi",
|
||||||
"fileapi",
|
"fileapi",
|
||||||
"namedpipeapi",
|
"namedpipeapi",
|
||||||
|
"processthreadsapi"
|
||||||
]}
|
]}
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
//! The purpose of this crate is to make it a bit more ergonomic for portable
|
||||||
|
//! applications that need to work with the platform level `RawFd` and
|
||||||
|
//! `RawHandle` types.
|
||||||
|
//! Rather than conditionally using `RawFd` and `RawHandle`, the `FileDescriptor`
|
||||||
|
//! type can be used to manage ownership, duplicate, read and write.
|
||||||
|
//! The `Pipe` type makes it more convenient to create a pipe and manage
|
||||||
|
//! the lifetime of both the read and write ends of that pipe.
|
||||||
use failure::Fallible;
|
use failure::Fallible;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
mod unix;
|
mod unix;
|
||||||
|
@ -5,12 +5,12 @@ use crate::{
|
|||||||
use failure::{bail, Fallible};
|
use failure::{bail, Fallible};
|
||||||
use std::io::{self, Error as IoError};
|
use std::io::{self, Error as IoError};
|
||||||
use std::os::windows::prelude::*;
|
use std::os::windows::prelude::*;
|
||||||
use std::os::windows::raw::HANDLE;
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use winapi::um::fileapi::*;
|
use winapi::um::fileapi::*;
|
||||||
use winapi::um::handleapi::*;
|
use winapi::um::handleapi::*;
|
||||||
use winapi::um::namedpipeapi::CreatePipe;
|
use winapi::um::namedpipeapi::CreatePipe;
|
||||||
use winapi::um::processthreadsapi::*;
|
use winapi::um::processthreadsapi::*;
|
||||||
|
use winapi::um::winnt::HANDLE;
|
||||||
|
|
||||||
/// `RawFileDescriptor` is a platform independent type alias for the
|
/// `RawFileDescriptor` is a platform independent type alias for the
|
||||||
/// underlying platform file descriptor type. It is primarily useful
|
/// underlying platform file descriptor type. It is primarily useful
|
||||||
@ -39,8 +39,8 @@ unsafe impl Send for OwnedHandle {}
|
|||||||
|
|
||||||
impl Drop for OwnedHandle {
|
impl Drop for OwnedHandle {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.handle != INVALID_HANDLE_VALUE && !self.handle.is_null() {
|
if self.handle != INVALID_HANDLE_VALUE as _ && !self.handle.is_null() {
|
||||||
unsafe { CloseHandle(self.handle) };
|
unsafe { CloseHandle(self.handle as _) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ impl OwnedHandle {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn dup_impl<F: AsRawFileDescriptor>(f: &F) -> Fallible<Self> {
|
pub(crate) fn dup_impl<F: AsRawFileDescriptor>(f: &F) -> Fallible<Self> {
|
||||||
let handle = f.as_raw_file_descriptor();
|
let handle = f.as_raw_file_descriptor();
|
||||||
if handle == INVALID_HANDLE_VALUE || handle.is_null() {
|
if handle == INVALID_HANDLE_VALUE as _ || handle.is_null() {
|
||||||
return Ok(OwnedHandle { handle });
|
return Ok(OwnedHandle { handle });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,13 +83,13 @@ impl OwnedHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AsRawHandle for OwnedHandle {
|
impl AsRawHandle for OwnedHandle {
|
||||||
fn as_raw_handle(&self) -> HANDLE {
|
fn as_raw_handle(&self) -> RawHandle {
|
||||||
self.handle
|
self.handle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoRawHandle for OwnedHandle {
|
impl IntoRawHandle for OwnedHandle {
|
||||||
fn into_raw_handle(self) -> HANDLE {
|
fn into_raw_handle(self) -> RawHandle {
|
||||||
let handle = self.handle;
|
let handle = self.handle;
|
||||||
std::mem::forget(self);
|
std::mem::forget(self);
|
||||||
handle
|
handle
|
||||||
@ -107,13 +107,13 @@ impl FileDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IntoRawHandle for FileDescriptor {
|
impl IntoRawHandle for FileDescriptor {
|
||||||
fn into_raw_handle(self) -> HANDLE {
|
fn into_raw_handle(self) -> RawHandle {
|
||||||
self.handle.into_raw_handle()
|
self.handle.into_raw_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRawHandle for FileDescriptor {
|
impl AsRawHandle for FileDescriptor {
|
||||||
fn as_raw_handle(&self) -> HANDLE {
|
fn as_raw_handle(&self) -> RawHandle {
|
||||||
self.handle.as_raw_handle()
|
self.handle.as_raw_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,17 +171,17 @@ impl io::Write for FileDescriptor {
|
|||||||
|
|
||||||
impl Pipe {
|
impl Pipe {
|
||||||
pub fn new() -> Fallible<Pipe> {
|
pub fn new() -> Fallible<Pipe> {
|
||||||
let mut read: HANDLE = INVALID_HANDLE_VALUE;
|
let mut read: HANDLE = INVALID_HANDLE_VALUE as _;
|
||||||
let mut write: HANDLE = INVALID_HANDLE_VALUE;
|
let mut write: HANDLE = INVALID_HANDLE_VALUE as _;
|
||||||
if unsafe { CreatePipe(&mut read, &mut write, ptr::null_mut(), 0) } == 0 {
|
if unsafe { CreatePipe(&mut read, &mut write, ptr::null_mut(), 0) } == 0 {
|
||||||
bail!("CreatePipe failed: {}", IoError::last_os_error());
|
bail!("CreatePipe failed: {}", IoError::last_os_error());
|
||||||
}
|
}
|
||||||
Ok(Pipe {
|
Ok(Pipe {
|
||||||
read: FileDescriptor {
|
read: FileDescriptor {
|
||||||
handle: OwnedHandle { handle: read },
|
handle: OwnedHandle { handle: read as _ },
|
||||||
},
|
},
|
||||||
write: FileDescriptor {
|
write: FileDescriptor {
|
||||||
handle: OwnedHandle { handle: write },
|
handle: OwnedHandle { handle: write as _ },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user