Finalize and register this device. # Errors Returns an error if device setup or creation fails.
(self)
| 219 | /// # Errors |
| 220 | /// Returns an error if device setup or creation fails. |
| 221 | pub fn build(self) -> io::Result<VirtualDevice> { |
| 222 | // Populate the uinput_setup struct |
| 223 | |
| 224 | let mut usetup = uinput_setup { |
| 225 | id: self.id.unwrap_or(DEFAULT_ID), |
| 226 | name: [0; UINPUT_MAX_NAME_SIZE], |
| 227 | ff_effects_max: self.ff_effects_max, |
| 228 | }; |
| 229 | |
| 230 | // SAFETY: either casting [u8] to [u8], or [u8] to [i8], which is the same size |
| 231 | let name_bytes = unsafe { &*(self.name as *const [u8] as *const [libc::c_char]) }; |
| 232 | // Panic if we're doing something really stupid |
| 233 | // + 1 for the null terminator; usetup.name was zero-initialized so there will be null |
| 234 | // bytes after the part we copy into |
| 235 | assert!(name_bytes.len() + 1 < UINPUT_MAX_NAME_SIZE); |
| 236 | usetup.name[..name_bytes.len()].copy_from_slice(name_bytes); |
| 237 | |
| 238 | VirtualDevice::new(self.fd, &usetup) |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | const DEFAULT_ID: input_id = input_id { |