Skip to content

Commit

Permalink
impl Sync for SerialPort trait
Browse files Browse the repository at this point in the history
  • Loading branch information
unlimitedsola committed Jan 23, 2025
1 parent ec256f0 commit 6d982c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ impl SerialPortBuilder {
///
/// This trait is all that's necessary to implement a new serial port driver
/// for a new platform.
pub trait SerialPort: Send + io::Read + io::Write {
pub trait SerialPort: Send + Sync + io::Read + io::Write {
// Port settings getters

/// Returns the name of this port if it exists.
Expand Down
10 changes: 10 additions & 0 deletions src/windows/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ pub struct COMPort {
port_name: Option<String>,
}

// The Windows [`HANDLE`] type is considered safe according to the standard library.
// See explanation on [`OwnedHandle`] in stdlib for more information.
//
// [`HANDLE`]: std::os::windows::raw::HANDLE
// [`OwnedHandle`]: std::os::windows::io::OwnedHandle
//
// In the future we might want to consider using `OwnedHandle` instead of `HANDLE` directly.
// At the time of writing, such work is blocked by this crate's MSRV (1.59.0) policy as
// `OwnedHandle` was stabilized in 1.63.0.
unsafe impl Send for COMPort {}
unsafe impl Sync for COMPort {}

impl COMPort {
/// Opens a COM port as a serial device.
Expand Down

0 comments on commit 6d982c1

Please sign in to comment.