Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: use of deprecated try macro #73

Open
Resonanz opened this issue Oct 4, 2023 · 1 comment
Open

error: use of deprecated try macro #73

Resonanz opened this issue Oct 4, 2023 · 1 comment

Comments

@Resonanz
Copy link

Resonanz commented Oct 4, 2023

From the example on the home page: https://github.com/dcuddeback/serial-rs/tree/master/serial

rustc -V --> rustc 1.72.1

   Compiling rust_serial v0.1.0 (C:\Users\r\GitHub\rust_serial)
error: use of deprecated `try` macro
  --> src\main.rs:18:5
   |
18 | /     try!(port.reconfigure(&|settings| {
19 | |         try!(settings.set_baud_rate(serial::Baud9600));
20 | |         settings.set_char_size(serial::Bits8);
21 | |         settings.set_parity(serial::ParityNone);
...  |
24 | |         Ok(())
25 | |     }));
   | |_______^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
@lolpro11
Copy link

extern crate serial;

use std::env;
use std::io;
use std::time::Duration;

use std::io::prelude::*;
use serial::prelude::*;

fn main() {
    for arg in env::args_os().skip(1) {
        let mut port = serial::open(&arg).unwrap();
        interact(&mut port).unwrap();
    }
}

fn interact<T: SerialPort>(port: &mut T) -> io::Result<()> {
    port.reconfigure(&|settings| {
        settings.set_baud_rate(serial::Baud9600)?;
        settings.set_char_size(serial::Bits8);
        settings.set_parity(serial::ParityNone);
        settings.set_stop_bits(serial::Stop1);
        settings.set_flow_control(serial::FlowNone);
        Ok(())
    })?;

    port.set_timeout(Duration::from_millis(1000))?;

    let mut buf: Vec<u8> = (0..255).collect();

    port.write(&buf[..])?;
    port.read(&mut buf[..])?;

    Ok(())
}

Use the ? operator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants