Rust 2018 edition changes
This commit is contained in:
parent
95cfd637b9
commit
f4083343da
@ -9,6 +9,8 @@ description = "Linux keyboard mapper"
|
||||
repository = "https://code.moparisthebest.com/moparisthebest/rusty-keys"
|
||||
keywords = ["linux", "input", "keyboard", "keymapper"]
|
||||
|
||||
edition = "2018"
|
||||
|
||||
include = [
|
||||
"src/**",
|
||||
"Cargo.toml",
|
||||
|
@ -5,7 +5,7 @@ use libc::c_int;
|
||||
use nix::{self, fcntl, unistd, errno::Errno};
|
||||
use nix::sys::stat;
|
||||
use ffi::*;
|
||||
use {Result as Res, Device};
|
||||
use crate::{Result as Res, Device};
|
||||
use std::collections::hash_map::Values;
|
||||
|
||||
#[cfg(feature = "udev")]
|
||||
@ -22,28 +22,12 @@ impl Builder {
|
||||
/// Create a builder from the specified path.
|
||||
pub fn open<P: AsRef<Path>>(path: P) -> Res<Self> {
|
||||
Ok(Builder {
|
||||
fd: try!(fcntl::open(path.as_ref(), fcntl::OFlag::O_WRONLY | fcntl::OFlag::O_NONBLOCK, stat::Mode::empty())),
|
||||
fd: fcntl::open(path.as_ref(), fcntl::OFlag::O_WRONLY | fcntl::OFlag::O_NONBLOCK, stat::Mode::empty())?,
|
||||
def: unsafe { mem::zeroed() },
|
||||
abs: None,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "udev")]
|
||||
/// Create a builder from the default path taken from udev.
|
||||
pub fn default() -> Res<Self> {
|
||||
let context = try!(udev::Context::new());
|
||||
let mut enumerator = try!(udev::Enumerator::new(&context));
|
||||
|
||||
try!(enumerator.match_subsystem("misc"));
|
||||
try!(enumerator.match_sysname("uinput"));
|
||||
|
||||
let device = try!(try!(enumerator.scan_devices())
|
||||
.next().ok_or(Error::NotFound));
|
||||
|
||||
Builder::open(try!(device.devnode().ok_or(Error::NotFound)))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "udev"))]
|
||||
/// Create a builder from `/dev/uinput`.
|
||||
pub fn default() -> Res<Self> {
|
||||
Builder::open("/dev/uinput")
|
||||
@ -51,11 +35,11 @@ impl Builder {
|
||||
|
||||
/// Set the name.
|
||||
pub fn name<T: AsRef<str>>(mut self, value: T) -> Res<Self> {
|
||||
let string = try!(CString::new(value.as_ref()));
|
||||
let string = CString::new(value.as_ref())?;
|
||||
let bytes = string.as_bytes_with_nul();
|
||||
|
||||
if bytes.len() > UINPUT_MAX_NAME_SIZE as usize {
|
||||
try!(Err(nix::Error::from_errno(Errno::EINVAL)));
|
||||
Err(nix::Error::from_errno(Errno::EINVAL))?;
|
||||
}
|
||||
|
||||
(&mut self.def.name)[..bytes.len()]
|
||||
@ -276,10 +260,10 @@ impl Builder {
|
||||
let ptr = &self.def as *const _ as *const u8;
|
||||
let size = mem::size_of_val(&self.def);
|
||||
|
||||
try!(unistd::write(self.fd, slice::from_raw_parts(ptr, size)));
|
||||
unistd::write(self.fd, slice::from_raw_parts(ptr, size))?;
|
||||
//todo: try!(Errno::result(ui_dev_create(self.fd)));
|
||||
// try1: Errno::result(ui_dev_create(self.fd)).unwrap();
|
||||
try!(Errno::result(ui_dev_create(self.fd)));
|
||||
Errno::result(ui_dev_create(self.fd))?;
|
||||
}
|
||||
|
||||
Ok(Device::new(self.fd))
|
||||
|
@ -2,7 +2,7 @@ use std::{mem, ptr, slice};
|
||||
use libc::{timeval, gettimeofday, input_event, c_int};
|
||||
use nix::{unistd, errno::Errno};
|
||||
use ffi::*;
|
||||
use {Result as Res};
|
||||
use crate::{Result as Res};
|
||||
|
||||
/// The virtual device.
|
||||
pub struct Device {
|
||||
@ -37,7 +37,7 @@ impl Device {
|
||||
let ptr = event as *const _ as *const u8;
|
||||
let size = mem::size_of_val(event);
|
||||
|
||||
try!(unistd::write(self.fd, slice::from_raw_parts(ptr, size)));
|
||||
unistd::write(self.fd, slice::from_raw_parts(ptr, size))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -65,8 +65,8 @@ impl Device {
|
||||
|
||||
/// Send a press and release event.
|
||||
pub fn click(&self, kind: c_int, code: c_int) -> Res<()> {
|
||||
try!(self.press(kind, code));
|
||||
try!(self.release(kind, code));
|
||||
self.press(kind, code)?;
|
||||
self.release(kind, code)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use libc::{input_event, c_int};
|
||||
use {Error,Result};
|
||||
use crate::{Error,Result};
|
||||
|
||||
ioctl_write_ptr!(eviocgrab, b'E', 0x90, c_int);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
use device::Device;
|
||||
use crate::Device;
|
||||
|
||||
use ffi::*;
|
||||
use libc::{c_int, input_event};
|
||||
@ -8,7 +8,7 @@ use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use {Error, Result};
|
||||
use crate::{Error, Result};
|
||||
|
||||
// 1 is down, 0 is up
|
||||
const DOWN: i32 = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user