@@ -2,7 +2,10 @@ use caw_core::{Sig, SigT};
22use caw_midi:: MidiMessages ;
33use midly:: live:: LiveEvent ;
44use nix:: sys:: termios:: BaudRate ;
5- use std:: { os:: fd:: OwnedFd , path:: Path } ;
5+ use std:: {
6+ os:: fd:: { AsFd , OwnedFd } ,
7+ path:: Path ,
8+ } ;
69
710pub struct MidiLiveSerial {
811 owned_fd : OwnedFd ,
@@ -45,16 +48,11 @@ impl MidiLiveSerial {
4548 termios:: { self , LocalFlags , SetArg } ,
4649 } ,
4750 } ;
48- let fd = fcntl:: open (
51+ let owned_fd = fcntl:: open (
4952 tty_path. as_ref ( ) ,
5053 OFlag :: O_RDONLY | OFlag :: O_NONBLOCK ,
5154 Mode :: empty ( ) ,
5255 ) ?;
53- let owned_fd = unsafe {
54- use std:: os:: fd:: FromRawFd ;
55- // fd is a valid file descriptor and the only cleanup it needs is close
56- OwnedFd :: from_raw_fd ( fd)
57- } ;
5856 let mut termios = termios:: tcgetattr ( & owned_fd) ?;
5957 termios. local_flags &= !( LocalFlags :: ECHO | LocalFlags :: ICANON ) ;
6058 let baud_rate = Self :: convert_baud_rate ( baud_rate) ?;
@@ -65,9 +63,8 @@ impl MidiLiveSerial {
6563
6664 fn read_byte ( & self ) -> anyhow:: Result < Option < u8 > > {
6765 use nix:: { errno:: Errno , unistd} ;
68- use std:: os:: fd:: AsRawFd ;
6966 let mut buf = [ 0 ] ;
70- let nbytes = match unistd:: read ( self . owned_fd . as_raw_fd ( ) , & mut buf) {
67+ let nbytes = match unistd:: read ( self . owned_fd . as_fd ( ) , & mut buf) {
7168 Ok ( nbytes) => nbytes,
7269 Err ( Errno :: EAGAIN ) => 0 ,
7370 Err ( e) => return Err ( e. into ( ) ) ,
0 commit comments