diff --git a/Cargo.toml b/Cargo.toml index 5fdc6f5..3c09b08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,12 +48,8 @@ version = "1.8.1" features = ["macros"] default-features = false -[target.'cfg(windows)'.dependencies] -serialport = { version = "4", default-features = false } -winapi = { version = "0.3", features = ["commapi", "fileapi", "handleapi", "winbase", "winnt"] } - [[example]] name = "serial_println" path = "examples/serial_println.rs" -required-features = ["rt", "codec"] \ No newline at end of file +required-features = ["rt", "codec"] diff --git a/src/lib.rs b/src/lib.rs index 51b145a..ff22e0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,6 +55,11 @@ pub type Result = mio_serial::Result; pub struct SerialStream { #[cfg(unix)] inner: AsyncFd, + // Named pipes and COM ports are actually two entirely different things that hardly have anything in common. + // The only thing they share is the opaque `HANDLE` type that can be fed into `CreateFileW`, `ReadFile`, `WriteFile`, etc. + // + // Both `mio` and `tokio` don't yet have any code to work on arbitrary HANDLEs. + // But they have code for dealing with named pipes, and we (ab)use that here to work on COM ports. #[cfg(windows)] inner: named_pipe::NamedPipeClient, // The com port is kept around for serialport related methods @@ -500,27 +505,22 @@ mod io { } } } -// -// -// + /// An extension trait for serialport::SerialPortBuilder /// -/// This trait adds two methods to SerialPortBuilder: +/// This trait adds one method to SerialPortBuilder: /// -/// - open_async /// - open_native_async /// -/// These methods mirror the `open` and `open_native` methods of SerialPortBuilder +/// This method mirrors the `open_native` method of SerialPortBuilder pub trait SerialPortBuilderExt { - // /// Open a cross-platform interface to the port with the specified settings - // fn open_async(self) -> Result>; - /// Open a platform-specific interface to the port with the specified settings - fn open_async(self) -> Result; + fn open_native_async(self) -> Result; } + impl SerialPortBuilderExt for SerialPortBuilder { /// Open a platform-specific interface to the port with the specified settings - fn open_async(self) -> Result { + fn open_native_async(self) -> Result { SerialStream::open(&self) } }