Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gnxlxnxx committed Jan 20, 2022
1 parent cb28b14 commit 6ff225f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
18 changes: 12 additions & 6 deletions serial-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ pub trait SerialPort: io::Read + io::Write {
/// })
/// }
/// ```
fn reconfigure(&mut self, setup: &Fn(&mut SerialPortSettings) -> ::Result<()>) -> ::Result<()>;
fn reconfigure(
&mut self,
setup: &dyn Fn(&mut dyn SerialPortSettings) -> ::Result<()>,
) -> ::Result<()>;

/// Sets the state of the RTS (Request To Send) control signal.
///
Expand Down Expand Up @@ -585,9 +588,9 @@ impl<T> SerialPort for T
}

fn configure(&mut self, settings: &PortSettings) -> ::Result<()> {
let mut device_settings = try!(T::read_settings(self));
let mut device_settings = T::read_settings(self)?;

try!(device_settings.set_baud_rate(settings.baud_rate));
device_settings.set_baud_rate(settings.baud_rate)?;
device_settings.set_char_size(settings.char_size);
device_settings.set_parity(settings.parity);
device_settings.set_stop_bits(settings.stop_bits);
Expand All @@ -596,9 +599,12 @@ impl<T> SerialPort for T
T::write_settings(self, &device_settings)
}

fn reconfigure(&mut self, setup: &Fn(&mut SerialPortSettings) -> ::Result<()>) -> ::Result<()> {
let mut device_settings = try!(T::read_settings(self));
try!(setup(&mut device_settings));
fn reconfigure(
&mut self,
setup: &dyn Fn(&mut dyn SerialPortSettings) -> ::Result<()>,
) -> ::Result<()> {
let mut device_settings = T::read_settings(self)?;
setup(&mut device_settings)?;
T::write_settings(self, &device_settings)
}

Expand Down
3 changes: 1 addition & 2 deletions serial-unix/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core;

use std::error::Error;
use std::ffi::CStr;
use std::io;
use std::str;
Expand Down Expand Up @@ -30,7 +29,7 @@ pub fn from_io_error(io_error: io::Error) -> core::Error {
match io_error.raw_os_error() {
Some(errno) => from_raw_os_error(errno),
None => {
let description = io_error.description().to_string();
let description = io_error.to_string();

core::Error::new(core::ErrorKind::Io(io_error.kind()), description)
}
Expand Down
8 changes: 4 additions & 4 deletions serial-unix/src/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ impl TTYPort {
}

// apply initial settings
let settings = try!(port.read_settings());
try!(port.write_settings(&settings));
let settings = port.read_settings()?;
port.write_settings(&settings)?;

Ok(port)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl AsRawFd for TTYPort {

impl io::Read for TTYPort {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
try!(super::poll::wait_read_fd(self.fd, self.timeout));
super::poll::wait_read_fd(self.fd, self.timeout)?;

let len = unsafe {
libc::read(self.fd, buf.as_ptr() as *mut c_void, buf.len() as size_t)
Expand All @@ -143,7 +143,7 @@ impl io::Read for TTYPort {

impl io::Write for TTYPort {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
try!(super::poll::wait_write_fd(self.fd, self.timeout));
super::poll::wait_write_fd(self.fd, self.timeout)?;

let len = unsafe {
libc::write(self.fd, buf.as_ptr() as *mut c_void, buf.len() as size_t)
Expand Down
2 changes: 1 addition & 1 deletion serial-windows/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl COMPort {
timeout: timeout,
};

try!(port.set_timeout(timeout));
port.set_timeout(timeout)?;
Ok(port)
}
else {
Expand Down

0 comments on commit 6ff225f

Please sign in to comment.