Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements to 5.4.0-beta1 #42

Merged
merged 4 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
required-features = ["rt", "codec"]
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ pub type Result<T> = mio_serial::Result<T>;
pub struct SerialStream {
#[cfg(unix)]
inner: AsyncFd<mio_serial::SerialStream>,
// 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
Expand Down Expand Up @@ -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
ColinFinck marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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<Box<dyn MioSerialPort>>;

/// Open a platform-specific interface to the port with the specified settings
fn open_async(self) -> Result<SerialStream>;
fn open_native_async(self) -> Result<SerialStream>;
}

impl SerialPortBuilderExt for SerialPortBuilder {
/// Open a platform-specific interface to the port with the specified settings
fn open_async(self) -> Result<SerialStream> {
fn open_native_async(self) -> Result<SerialStream> {
SerialStream::open(&self)
}
}