-
-
Save dbrgn/3f3509acbb8cc9fdde229138858e5d0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit a1ba9ad57b356fa6d492cb8b056f5677cb08f9a7 | |
Author: Danilo Bargen <mail@dbrgn.ch> | |
Date: Tue May 14 21:53:25 2019 +0200 | |
Switch from serial to serial_core | |
The crate has been split up. | |
diff --git a/Cargo.toml b/Cargo.toml | |
index 0163c76..fbdbf4c 100644 | |
--- a/Cargo.toml | |
+++ b/Cargo.toml | |
@@ -13,7 +13,7 @@ embedded-hal = { version = "0.2.0", features = ["unproven"] } | |
i2cdev = "0.4.1" | |
spidev = "0.3.0" | |
sysfs_gpio = "0.5.1" | |
-serial = "0.4.0" | |
+serial-core = "0.4.0" | |
nb = "0.1.1" | |
[dev-dependencies] | |
diff --git a/src/lib.rs b/src/lib.rs | |
index 589b4fd..2ad6e02 100644 | |
--- a/src/lib.rs | |
+++ b/src/lib.rs | |
@@ -18,7 +18,7 @@ extern crate embedded_hal as hal; | |
pub extern crate i2cdev; | |
pub extern crate spidev; | |
pub extern crate sysfs_gpio; | |
-pub extern crate serial; | |
+pub extern crate serial_core; | |
pub extern crate nb; | |
use std::io::{self, Write}; | |
diff --git a/src/serial_impl.rs b/src/serial_impl.rs | |
index 81a2796..aedad99 100644 | |
--- a/src/serial_impl.rs | |
+++ b/src/serial_impl.rs | |
@@ -1,18 +1,17 @@ | |
//! Implementation of [`Serial`](https://docs.rs/embedded-hal/0.2.1/embedded_hal/serial/index.html) | |
- | |
use nb; | |
-use ::hal::serial::{Read, Write}; | |
-use ::serial; | |
-/// Newtype around [`serial::SystemPort`] that implements the `embedded-hal` traits | |
-pub struct Serial(pub serial::SystemPort); | |
+use ::serial_core; | |
+ | |
+ | |
+/// Newtype around [`serial_core::SerialPort`] that implements the `embedded-hal` traits. | |
+pub struct Serial(pub serial_core::SerialPort); | |
-impl Read<u8> for Serial { | |
- type Error = serial::Error; | |
+impl ::hal::serial::Read<u8> for Serial { | |
+ type Error = serial_core::Error; | |
fn read(&mut self) -> nb::Result<u8, Self::Error> { | |
- use std::io::Read; | |
let mut buffer = [0; 1]; | |
let bytes_read = self.0.read(&mut buffer) | |
.map_err(|err| nb::Error::Other(Self::Error::from(err)))?; | |
@@ -24,18 +23,16 @@ impl Read<u8> for Serial { | |
} | |
} | |
-impl Write<u8> for Serial { | |
- type Error = serial::Error; | |
+impl ::hal::serial::Write<u8> for Serial { | |
+ type Error = serial_core::Error; | |
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { | |
- use std::io::Write; | |
self.0.write(&[word]) | |
.map_err(|err| nb::Error::Other(Self::Error::from(err)))?; | |
Ok(()) | |
} | |
fn flush(&mut self) -> nb::Result<(), Self::Error> { | |
- use std::io::Write; | |
self.0.flush() | |
.map_err(|err| nb::Error::Other(Self::Error::from(err))) | |
} | |
@@ -62,7 +59,7 @@ mod test { | |
let name = unsafe {CStr::from_ptr(name.as_ptr())}; | |
assert_eq!(result, 0); | |
println!("{:?}", name); | |
- let mut port: Box<Read<u8, Error=serial::Error>> = Box::new(Serial(serial::open(name.to_str().unwrap()).unwrap())); | |
+ let mut port: Box<Read<u8, Error=serial_core::Error>> = Box::new(Serial(serial_core::open(name.to_str().unwrap()).unwrap())); | |
port.read().unwrap(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment