diff --git a/src/lib.rs b/src/lib.rs index 79d0f377..6580efd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -425,7 +425,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. diff --git a/src/windows/com.rs b/src/windows/com.rs index fa1abbca..52778a7d 100644 --- a/src/windows/com.rs +++ b/src/windows/com.rs @@ -32,7 +32,15 @@ pub struct COMPort { port_name: Option, } +// The Windows `HANDLE` type is considered safe according to the standard library. +// See the explanation below in stdlib for more information: +// https://github.com/rust-lang/rust/blob/f4f0fafd0c7849e162eddbc69fa5fe82dbec28c7/library/std/src/os/windows/io/handle.rs#L111-L115 +// +// 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.