From 98183712f923e7426c27a1ba1d3a1528cb601450 Mon Sep 17 00:00:00 2001 From: Jeff Hiner Date: Tue, 23 Feb 2021 17:27:05 -0700 Subject: [PATCH] Switch external-facing APIs from CString to &str --- src/lib.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e86110d..e4df264 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -165,9 +165,9 @@ pub enum Error { pub struct Device { file: File, ty: Types, - name: Option, - phys: Option, - uniq: Option, + name: Option, + phys: Option, + uniq: Option, id: input_id, props: Props, driver_version: (u8, u8, u8), @@ -330,16 +330,16 @@ impl Device { self.ty } - pub fn name(&self) -> &Option { - &self.name + pub fn name(&self) -> Option<&str> { + self.name.as_deref() } - pub fn physical_path(&self) -> &Option { - &self.phys + pub fn physical_path(&self) -> Option<&str> { + self.phys.as_deref() } - pub fn unique_name(&self) -> &Option { - &self.uniq + pub fn unique_name(&self) -> Option<&str> { + self.uniq.as_deref() } pub fn input_id(&self) -> input_id { @@ -410,9 +410,12 @@ impl Device { unsafe { eviocgbit_type(file.as_raw_fd(), &mut ty)? }; let ty = Types::from_bits(ty).expect("evdev: unexpected type bits! report a bug"); - let name = ioctl_get_cstring(eviocgname, file.as_raw_fd()); - let phys = ioctl_get_cstring(eviocgphys, file.as_raw_fd()); - let uniq = ioctl_get_cstring(eviocguniq, file.as_raw_fd()); + let name = ioctl_get_cstring(eviocgname, file.as_raw_fd()) + .map(|s| s.to_string_lossy().into_owned()); + let phys = ioctl_get_cstring(eviocgphys, file.as_raw_fd()) + .map(|s| s.to_string_lossy().into_owned()); + let uniq = ioctl_get_cstring(eviocguniq, file.as_raw_fd()) + .map(|s| s.to_string_lossy().into_owned()); let id = unsafe { let mut id = MaybeUninit::uninit();