Skip to content

Commit

Permalink
Merge pull request #70 from ShaneMurphy2/from-tty
Browse files Browse the repository at this point in the history
Allow constructing a SerialStream from a TTYPort.

Happy new year 🎉
  • Loading branch information
estokes authored Dec 31, 2024
2 parents 2a2c77c + 3fa55df commit d749b02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ version = "0.4"
[dependencies.cfg-if]
version = "1"

[dependencies.serialport]
version = "4"
default-features = false

[dev-dependencies]
anyhow = "1.0.91"

Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use mio_serial::{

use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

use std::convert::TryFrom;

Check failure on line 18 in src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-clippy (stable, windows-latest)

unused import: `std::convert::TryFrom`
use std::io::{Read, Result as IoResult, Write};
use std::pin::Pin;
use std::task::{Context, Poll};
Expand Down Expand Up @@ -488,6 +489,18 @@ impl Write for SerialStream {
}
}

#[cfg(unix)]
impl TryFrom<serialport::TTYPort> for SerialStream {
type Error = Error;

fn try_from(value: serialport::TTYPort) -> std::result::Result<Self, Self::Error> {
let port = mio_serial::SerialStream::try_from(value)?;
Ok(Self {
inner: AsyncFd::new(port)?,
})
}
}

#[cfg(unix)]
mod sys {
use super::SerialStream;
Expand Down

0 comments on commit d749b02

Please sign in to comment.