Buttplug sex toy control library

chore: Run clippy --fix

+294 -367
+1 -1
crates/buttplug_client/src/client_event_loop.rs
··· 218 218 continue; 219 219 } 220 220 trace!("Device added, updating map and sending to client"); 221 - let info = DeviceMessageInfoV4::from(dev.1.clone()); 221 + let info = dev.1.clone(); 222 222 let device = self.create_client_device(&info); 223 223 self.send_client_event(ButtplugClientEvent::DeviceAdded(device)); 224 224 }
+9 -9
crates/buttplug_client/src/device/command.rs
··· 5 5 Float(f64), 6 6 } 7 7 8 - impl Into<ClientDeviceCommandValue> for u32 { 9 - fn into(self) -> ClientDeviceCommandValue { 10 - ClientDeviceCommandValue::Int(self) 8 + impl From<u32> for ClientDeviceCommandValue { 9 + fn from(val: u32) -> Self { 10 + ClientDeviceCommandValue::Int(val) 11 11 } 12 12 } 13 13 14 - impl Into<ClientDeviceCommandValue> for f64 { 15 - fn into(self) -> ClientDeviceCommandValue { 16 - ClientDeviceCommandValue::Float(self) 14 + impl From<f64> for ClientDeviceCommandValue { 15 + fn from(val: f64) -> Self { 16 + ClientDeviceCommandValue::Float(val) 17 17 } 18 18 } 19 19 ··· 42 42 PositionWithDurationFloat(f64, u32), 43 43 } 44 44 45 - impl Into<OutputType> for &ClientDeviceOutputCommand { 46 - fn into(self) -> OutputType { 47 - match self { 45 + impl From<&ClientDeviceOutputCommand> for OutputType { 46 + fn from(val: &ClientDeviceOutputCommand) -> Self { 47 + match val { 48 48 ClientDeviceOutputCommand::Vibrate(_) | ClientDeviceOutputCommand::VibrateFloat(_) => { 49 49 OutputType::Vibrate 50 50 }
+1 -1
crates/buttplug_client/src/device/device.rs
··· 127 127 index, 128 128 device_features: device_features 129 129 .iter() 130 - .map(|(i, x)| (*i, ClientDeviceFeature::new(index, *i, &x, message_sender))) 130 + .map(|(i, x)| (*i, ClientDeviceFeature::new(index, *i, x, message_sender))) 131 131 .collect(), 132 132 event_loop_sender: message_sender.clone(), 133 133 internal_event_sender: event_sender,
+11 -17
crates/buttplug_client/src/device/feature.rs
··· 84 84 feature_output: &dyn DeviceFeatureOutputLimits, 85 85 float_amt: f64, 86 86 ) -> Result<u32, ButtplugClientError> { 87 - if float_amt < 0.0f64 || float_amt > 1.0f64 { 87 + if !(0.0f64..=1.0f64).contains(&float_amt) { 88 88 Err(ButtplugClientError::ButtplugOutputCommandConversionError( 89 89 "Float values must be between 0.0 and 1.0".to_owned(), 90 90 )) ··· 196 196 &self, 197 197 client_device_command: &ClientDeviceOutputCommand, 198 198 ) -> ButtplugClientResultFuture { 199 - match self.convert_client_cmd_to_output_cmd(&client_device_command) { 199 + match self.convert_client_cmd_to_output_cmd(client_device_command) { 200 200 Ok(cmd) => self.event_loop_sender.send_message_expect_ok(cmd.into()), 201 201 Err(e) => future::ready(Err(e)).boxed(), 202 202 } ··· 289 289 } 290 290 291 291 pub fn subscribe_sensor(&self, sensor_type: InputType) -> ButtplugClientResultFuture { 292 - if let Some(sensor_map) = self.feature.input() { 293 - if let Some(sensor) = sensor_map.get(sensor_type) { 294 - if sensor 292 + if let Some(sensor_map) = self.feature.input() 293 + && let Some(sensor) = sensor_map.get(sensor_type) 294 + && sensor 295 295 .input_commands() 296 296 .contains(&InputCommandType::Subscribe) 297 297 { ··· 304 304 .into(); 305 305 return self.event_loop_sender.send_message_expect_ok(msg); 306 306 } 307 - } 308 - } 309 307 create_boxed_future_client_error( 310 308 ButtplugDeviceError::MessageNotSupported(ButtplugDeviceMessageNameV4::InputCmd.to_string()) 311 309 .into(), ··· 313 311 } 314 312 315 313 pub fn unsubscribe_sensor(&self, sensor_type: InputType) -> ButtplugClientResultFuture { 316 - if let Some(sensor_map) = self.feature.input() { 317 - if let Some(sensor) = sensor_map.get(sensor_type) { 318 - if sensor 314 + if let Some(sensor_map) = self.feature.input() 315 + && let Some(sensor) = sensor_map.get(sensor_type) 316 + && sensor 319 317 .input_commands() 320 318 .contains(&InputCommandType::Subscribe) 321 319 { ··· 328 326 .into(); 329 327 return self.event_loop_sender.send_message_expect_ok(msg); 330 328 } 331 - } 332 - } 333 329 create_boxed_future_client_error( 334 330 ButtplugDeviceError::MessageNotSupported(ButtplugDeviceMessageNameV4::InputCmd.to_string()) 335 331 .into(), ··· 337 333 } 338 334 339 335 fn read_sensor(&self, sensor_type: InputType) -> ButtplugClientResultFuture<InputTypeData> { 340 - if let Some(sensor_map) = self.feature.input() { 341 - if let Some(sensor) = sensor_map.get(sensor_type) { 342 - if sensor.input_commands().contains(&InputCommandType::Read) { 336 + if let Some(sensor_map) = self.feature.input() 337 + && let Some(sensor) = sensor_map.get(sensor_type) 338 + && sensor.input_commands().contains(&InputCommandType::Read) { 343 339 let msg = InputCmdV4::new( 344 340 self.device_index, 345 341 self.feature_index, ··· 371 367 } 372 368 .boxed(); 373 369 } 374 - } 375 - } 376 370 create_boxed_future_client_error( 377 371 ButtplugDeviceError::MessageNotSupported(ButtplugDeviceMessageNameV4::InputCmd.to_string()) 378 372 .into(),
+1 -1
crates/buttplug_core/src/connector/remote_connector.rs
··· 238 238 // If we connect successfully, we get back the channel from the transport 239 239 // to send outgoing messages and receieve incoming events, all serialized. 240 240 Ok(()) => { 241 - let _ = async_manager::spawn(async move { 241 + async_manager::spawn(async move { 242 242 remote_connector_event_loop::< 243 243 TransportType, 244 244 SerializerType,
+2 -3
crates/buttplug_core/src/message/serializer/json_serializer.rs
··· 52 52 for msg in stream { 53 53 match msg { 54 54 Ok(json_msg) => { 55 - if let Some(validator) = validator { 56 - if !validator.is_valid(&json_msg) { 55 + if let Some(validator) = validator 56 + && !validator.is_valid(&json_msg) { 57 57 // If is_valid fails, re-run validation to get our error message. 58 58 let e = validator 59 59 .validate(&json_msg) ··· 62 62 "Error during JSON Schema Validation - Message: {json_msg} - Error: {e:?}" 63 63 ))); 64 64 } 65 - } 66 65 match serde_json::from_value::<Vec<T>>(json_msg) { 67 66 Ok(mut msg_vec) => { 68 67 for msg in msg_vec.iter_mut() {
+1 -4
crates/buttplug_core/src/message/v4/spec_enums.rs
··· 80 80 81 81 impl ButtplugMessageFinalizer for ButtplugServerMessageV4 { 82 82 fn finalize(&mut self) { 83 - match self { 84 - ButtplugServerMessageV4::DeviceList(dl) => dl.finalize(), 85 - _ => (), 86 - } 83 + if let ButtplugServerMessageV4::DeviceList(dl) = self { dl.finalize() } 87 84 } 88 85 } 89 86
+1 -1
crates/buttplug_server/src/device/hardware/mod.rs
··· 282 282 name: name.to_owned(), 283 283 address: address.to_owned(), 284 284 endpoints: endpoints.into(), 285 - message_gap: message_gap.clone(), 285 + message_gap: *message_gap, 286 286 internal_impl, 287 287 requires_keepalive, 288 288 last_write_time: Arc::new(RwLock::new(Instant::now())),
+5 -5
crates/buttplug_server/src/device/protocol.rs
··· 364 364 _feature_index: u32, 365 365 _feature_id: Uuid, 366 366 _sensor_type: InputType, 367 - ) -> BoxFuture<Result<(), ButtplugDeviceError>> { 367 + ) -> BoxFuture<'_, Result<(), ButtplugDeviceError>> { 368 368 future::ready(Err(ButtplugDeviceError::UnhandledCommand( 369 369 "Command not implemented for this protocol: InputCmd (Subscribe)".to_string(), 370 370 ))) ··· 377 377 _feature_index: u32, 378 378 _feature_id: Uuid, 379 379 _sensor_type: InputType, 380 - ) -> BoxFuture<Result<(), ButtplugDeviceError>> { 380 + ) -> BoxFuture<'_, Result<(), ButtplugDeviceError>> { 381 381 future::ready(Err(ButtplugDeviceError::UnhandledCommand( 382 382 "Command not implemented for this protocol: InputCmd (Unsubscribe)".to_string(), 383 383 ))) ··· 391 391 feature_index: u32, 392 392 feature_id: Uuid, 393 393 sensor_type: InputType, 394 - ) -> BoxFuture<Result<InputReadingV4, ButtplugDeviceError>> { 394 + ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> { 395 395 match sensor_type { 396 396 InputType::Battery => { 397 397 self.handle_battery_level_cmd(device_index, device, feature_index, feature_id) ··· 411 411 device: Arc<Hardware>, 412 412 feature_index: u32, 413 413 feature_id: Uuid, 414 - ) -> BoxFuture<Result<InputReadingV4, ButtplugDeviceError>> { 414 + ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> { 415 415 // If we have a standardized BLE Battery endpoint, handle that above the 416 416 // protocol, as it'll always be the same. 417 417 if device.endpoints().contains(&Endpoint::RxBLEBattery) { ··· 443 443 _device: Arc<Hardware>, 444 444 _feature_index: u32, 445 445 _feature_id: Uuid, 446 - ) -> BoxFuture<Result<(), ButtplugDeviceError>> { 446 + ) -> BoxFuture<'_, Result<(), ButtplugDeviceError>> { 447 447 future::ready(Err(ButtplugDeviceError::UnhandledCommand( 448 448 "Command not implemented for this protocol: SensorReadCmd".to_string(), 449 449 )))
+3 -3
crates/buttplug_server/src/device/protocol_impl/galaku.rs
··· 194 194 _feature_index: u32, 195 195 feature_id: Uuid, 196 196 sensor_type: InputType, 197 - ) -> BoxFuture<Result<(), ButtplugDeviceError>> { 197 + ) -> BoxFuture<'_, Result<(), ButtplugDeviceError>> { 198 198 match sensor_type { 199 199 InputType::Battery => { 200 200 async move { ··· 221 221 _feature_index: u32, 222 222 feature_id: Uuid, 223 223 sensor_type: InputType, 224 - ) -> BoxFuture<Result<(), ButtplugDeviceError>> { 224 + ) -> BoxFuture<'_, Result<(), ButtplugDeviceError>> { 225 225 match sensor_type { 226 226 InputType::Battery => { 227 227 async move { ··· 248 248 device: Arc<Hardware>, 249 249 feature_index: u32, 250 250 feature_id: Uuid, 251 - ) -> BoxFuture<Result<InputReadingV4, ButtplugDeviceError>> { 251 + ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> { 252 252 let data: Vec<u32> = vec![90, 0, 0, 1, 19, 0, 0, 0, 0, 0]; 253 253 let mut device_notification_receiver = device.event_stream(); 254 254 async move {
+2 -3
crates/buttplug_server/src/device/protocol_impl/hgod.rs
··· 76 76 loop { 77 77 let speed = data.load(Ordering::Relaxed); 78 78 let command = vec![0x55, 0x04, 0, 0, 0, speed]; 79 - if speed > 0 { 80 - if let Err(e) = device 79 + if speed > 0 80 + && let Err(e) = device 81 81 .write_value(&HardwareWriteCmd::new( 82 82 &[HGOD_PROTOCOL_UUID], 83 83 Endpoint::Tx, ··· 92 92 ); 93 93 break; 94 94 } 95 - } 96 95 sleep(Duration::from_millis(HGOD_COMMAND_DELAY_MS)).await; 97 96 } 98 97 }
+4 -5
crates/buttplug_server/src/device/protocol_impl/kgoal_boost.rs
··· 60 60 feature_index: u32, 61 61 feature_id: Uuid, 62 62 _sensor_type: InputType, 63 - ) -> BoxFuture<Result<(), ButtplugDeviceError>> { 63 + ) -> BoxFuture<'_, Result<(), ButtplugDeviceError>> { 64 64 if self.subscribed_sensors.contains(&feature_index) { 65 65 return future::ready(Ok(())).boxed(); 66 66 } ··· 88 88 if sender.receiver_count() == 0 || stream_sensors.is_empty() { 89 89 return; 90 90 } 91 - if let HardwareEvent::Notification(_, endpoint, data) = info { 92 - if endpoint == Endpoint::RxPressure { 91 + if let HardwareEvent::Notification(_, endpoint, data) = info 92 + && endpoint == Endpoint::RxPressure { 93 93 if data.len() < 7 { 94 94 // Not even sure how this would happen, error and continue on. 95 95 error!("KGoal Boost data not expected length!"); ··· 135 135 return; 136 136 } 137 137 } 138 - } 139 138 } 140 139 }); 141 140 } ··· 151 150 feature_index: u32, 152 151 feature_id: Uuid, 153 152 _sensor_type: InputType, 154 - ) -> BoxFuture<Result<(), ButtplugDeviceError>> { 153 + ) -> BoxFuture<'_, Result<(), ButtplugDeviceError>> { 155 154 if !self.subscribed_sensors.contains(&feature_index) { 156 155 return future::ready(Ok(())).boxed(); 157 156 }
+1 -1
crates/buttplug_server/src/device/protocol_impl/kiiroo_prowand.rs
··· 54 54 device: Arc<Hardware>, 55 55 feature_index: u32, 56 56 feature_id: Uuid, 57 - ) -> BoxFuture<Result<InputReadingV4, ButtplugDeviceError>> { 57 + ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> { 58 58 debug!("Trying to get battery reading."); 59 59 let msg = HardwareReadCmd::new(feature_id, Endpoint::RxBLEBattery, 20, 0); 60 60 let fut = device.read_value(&msg);
+1 -1
crates/buttplug_server/src/device/protocol_impl/kiiroo_spot.rs
··· 47 47 device: Arc<Hardware>, 48 48 feature_index: u32, 49 49 feature_id: Uuid, 50 - ) -> BoxFuture<Result<InputReadingV4, ButtplugDeviceError>> { 50 + ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> { 51 51 debug!("Trying to get battery reading."); 52 52 let msg = HardwareReadCmd::new(feature_id, Endpoint::RxBLEBattery, 20, 0); 53 53 let fut = device.read_value(&msg);
+1 -1
crates/buttplug_server/src/device/protocol_impl/kiiroo_v21.rs
··· 95 95 device: Arc<Hardware>, 96 96 feature_index: u32, 97 97 feature_id: Uuid, 98 - ) -> BoxFuture<Result<InputReadingV4, ButtplugDeviceError>> { 98 + ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> { 99 99 debug!("Trying to get battery reading."); 100 100 // Reading the "whitelist" endpoint for this device retrieves the battery level, 101 101 // which is byte 5. All other bytes of the 20-byte result are unknown.
+4 -4
crates/buttplug_server/src/device/protocol_impl/lovehoney_desire.rs
··· 61 61 impl LovehoneyDesire { 62 62 fn new(num_vibrators: u8) -> Self { 63 63 Self { 64 - current_commands: std::iter::repeat_with(|| AtomicU8::default()) 64 + current_commands: std::iter::repeat_with(AtomicU8::default) 65 65 .take(num_vibrators as usize) 66 66 .collect(), 67 67 } ··· 104 104 LOVEHONEY_DESIRE_VIBE2_PROTOCOL_UUID, 105 105 ], 106 106 Endpoint::Tx, 107 - vec![0xF3, 0, speed0 as u8], 107 + vec![0xF3, 0, speed0], 108 108 true, 109 109 ) 110 110 .into(), ··· 114 114 HardwareWriteCmd::new( 115 115 &[LOVEHONEY_DESIRE_PROTOCOL_UUID], 116 116 Endpoint::Tx, 117 - vec![0xF3, 1, speed0 as u8], 117 + vec![0xF3, 1, speed0], 118 118 true, 119 119 ) 120 120 .into(), 121 121 HardwareWriteCmd::new( 122 122 &[LOVEHONEY_DESIRE_VIBE2_PROTOCOL_UUID], 123 123 Endpoint::Tx, 124 - vec![0xF3, 2, speed1 as u8], 124 + vec![0xF3, 2, speed1], 125 125 true, 126 126 ) 127 127 .into(),
+1 -1
crates/buttplug_server/src/device/protocol_impl/magic_motion_v4.rs
··· 57 57 impl MagicMotionV4 { 58 58 fn new(num_vibrators: u8) -> Self { 59 59 Self { 60 - current_commands: std::iter::repeat_with(|| AtomicU8::default()) 60 + current_commands: std::iter::repeat_with(AtomicU8::default) 61 61 .take(num_vibrators as usize) 62 62 .collect(), 63 63 }
+2 -2
crates/buttplug_server/src/device/protocol_impl/monsterpub.rs
··· 161 161 162 162 impl MonsterPub { 163 163 pub fn new(tx: Endpoint, num_outputs: u32) -> Self { 164 - let speeds: Vec<AtomicU8> = std::iter::repeat_with(|| AtomicU8::default()) 164 + let speeds: Vec<AtomicU8> = std::iter::repeat_with(AtomicU8::default) 165 165 .take(num_outputs as usize) 166 166 .collect(); 167 167 Self { tx, speeds } ··· 176 176 } 177 177 for cmd in self.speeds.iter() { 178 178 let speed = cmd.load(Ordering::Relaxed); 179 - data.push(speed as u8); 179 + data.push(speed); 180 180 if speed != 0 { 181 181 stop = false; 182 182 }
+1 -1
crates/buttplug_server/src/device/protocol_impl/mysteryvibe.rs
··· 77 77 impl MysteryVibe { 78 78 pub fn new(vibrator_count: u8) -> Self { 79 79 Self { 80 - speeds: std::iter::repeat_with(|| AtomicU8::default()) 80 + speeds: std::iter::repeat_with(AtomicU8::default) 81 81 .take(vibrator_count as usize) 82 82 .collect(), 83 83 }
+1 -1
crates/buttplug_server/src/device/protocol_impl/nintendo_joycon.rs
··· 17 17 use async_trait::async_trait; 18 18 use buttplug_core::{ 19 19 errors::ButtplugDeviceError, 20 - util::{self, async_manager}, 20 + util::async_manager, 21 21 }; 22 22 use buttplug_server_device_config::{ 23 23 Endpoint,
+6 -7
crates/buttplug_server/src/device/protocol_impl/sensee_v2.rs
··· 69 69 .iter() 70 70 .enumerate() 71 71 .for_each(|(i, x)| { 72 - if let Some(output_map) = x.output() { 73 - if output_map.contains(output_type) { 72 + if let Some(output_map) = x.output() 73 + && output_map.contains(output_type) { 74 74 map.insert(i as u32, AtomicU8::new(0)); 75 75 } 76 - } 77 76 }); 78 77 map 79 78 }; ··· 132 131 fn compile_command(&self) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 133 132 let mut data = vec![]; 134 133 data.push( 135 - if self.vibe_map.len() != 0 { 1 } else { 0 } 136 - + if self.thrust_map.len() != 0 { 1 } else { 0 } 137 - + if self.suck_map.len() != 0 { 1 } else { 0 } as u8, 134 + if !self.vibe_map.is_empty() { 1 } else { 0 } 135 + + if !self.thrust_map.is_empty() { 1 } else { 0 } 136 + + if !self.suck_map.is_empty() { 1 } else { 0 } as u8, 138 137 ); 139 138 let mut data_add = |i, m: &HashMap<u32, AtomicU8>| { 140 - if m.len() > 0 { 139 + if !m.is_empty() { 141 140 data.push(i); 142 141 data.push(m.len() as u8); 143 142 for (i, (_, v)) in m.iter().enumerate() {
+2 -2
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_iker.rs
··· 51 51 HardwareWriteCmd::new( 52 52 &[feature_id], 53 53 Endpoint::Tx, 54 - [0x55, 0x03, 0x03, 0x00, 0x01, vibe0 as u8].to_vec(), 54 + [0x55, 0x03, 0x03, 0x00, 0x01, { vibe0 }].to_vec(), 55 55 false, 56 56 ) 57 57 .into(), ··· 61 61 HardwareWriteCmd::new( 62 62 &[feature_id], 63 63 Endpoint::Tx, 64 - [0x55, 0x07, 0x00, 0x00, vibe1 as u8, 0x00].to_vec(), 64 + [0x55, 0x07, 0x00, 0x00, { vibe1 }, 0x00].to_vec(), 65 65 false, 66 66 ) 67 67 .into(),
+1 -1
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_v5.rs
··· 57 57 } else { 58 58 0x01 59 59 }, 60 - vibe1.max(vibe2) as u8, 60 + { vibe1.max(vibe2) }, 61 61 ] 62 62 .to_vec(), 63 63 false,
+2 -2
crates/buttplug_server/src/device/protocol_impl/svakom/svakom_v6.rs
··· 110 110 } else { 111 111 0x01 112 112 }, 113 - vibe1.max(vibe2) as u8, 113 + { vibe1.max(vibe2) }, 114 114 0x00, 115 115 ] 116 116 .to_vec(), ··· 130 130 0x00, 131 131 0x00, 132 132 if vibe3 == 0 { 0x00 } else { 0x01 }, 133 - vibe3 as u8, 133 + { vibe3 }, 134 134 0x00, 135 135 ] 136 136 .to_vec(),
+3 -3
crates/buttplug_server/src/device/protocol_impl/vibratissimo.rs
··· 84 84 .filter(|x| { 85 85 x.output() 86 86 .as_ref() 87 - .map_or(false, |x| x.contains(OutputType::Vibrate)) 87 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 88 88 }) 89 89 .count() as u8; 90 - Ok(Arc::new(Vibratissimo::new(num_vibrators as u8))) 90 + Ok(Arc::new(Vibratissimo::new(num_vibrators))) 91 91 } 92 92 } 93 93 ··· 97 97 98 98 impl Vibratissimo { 99 99 fn new(num_vibrators: u8) -> Self { 100 - let speeds: Vec<AtomicU8> = std::iter::repeat_with(|| AtomicU8::default()) 100 + let speeds: Vec<AtomicU8> = std::iter::repeat_with(AtomicU8::default) 101 101 .take(num_vibrators as usize) 102 102 .collect(); 103 103 Self { speeds }
+2 -2
crates/buttplug_server/src/device/protocol_impl/vorze_sa/piston.rs
··· 57 57 58 58 self 59 59 .previous_position 60 - .store(position as u8, Ordering::Relaxed); 60 + .store(position, Ordering::Relaxed); 61 61 62 62 Ok(vec![ 63 63 HardwareWriteCmd::new( 64 64 &[feature_id], 65 65 Endpoint::Tx, 66 - vec![VorzeDevice::Piston as u8, position as u8, speed], 66 + vec![VorzeDevice::Piston as u8, position, speed], 67 67 true, 68 68 ) 69 69 .into(),
+1 -1
crates/buttplug_server/src/device/protocol_impl/wevibe.rs
··· 63 63 .filter(|x| { 64 64 x.output() 65 65 .as_ref() 66 - .map_or(false, |x| x.contains(OutputType::Vibrate)) 66 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 67 67 }) 68 68 .count() as u8; 69 69 Ok(Arc::new(WeVibe::new(num_vibrators)))
+1 -1
crates/buttplug_server/src/device/protocol_impl/wevibe8bit.rs
··· 50 50 .filter(|x| { 51 51 x.output() 52 52 .as_ref() 53 - .map_or(false, |x| x.contains(OutputType::Vibrate)) 53 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 54 54 }) 55 55 .count() as u8; 56 56 Ok(Arc::new(WeVibe8Bit::new(num_vibrators)))
+1 -1
crates/buttplug_server/src/device/protocol_impl/wevibe_chorus.rs
··· 50 50 .filter(|x| { 51 51 x.output() 52 52 .as_ref() 53 - .map_or(false, |x| x.contains(OutputType::Vibrate)) 53 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 54 54 }) 55 55 .count() as u8; 56 56 Ok(Arc::new(WeVibeChorus::new(num_vibrators)))
+1 -1
crates/buttplug_server/src/device/protocol_impl/xinput.rs
··· 67 67 feature_index: u32, 68 68 feature_id: uuid::Uuid, 69 69 _sensor_type: message::InputType, 70 - ) -> BoxFuture<Result<InputReadingV4, ButtplugDeviceError>> { 70 + ) -> BoxFuture<'_, Result<InputReadingV4, ButtplugDeviceError>> { 71 71 async move { 72 72 let reading = device 73 73 .read_value(&HardwareReadCmd::new(feature_id, Endpoint::Rx, 0, 0))
+12 -18
crates/buttplug_server/src/device/server_device.rs
··· 213 213 let device = Self::new(identifier, handler, hardware, &attrs); 214 214 215 215 // If we need a keepalive with a packet replay, set this up via stopping the device on connect. 216 - if (requires_keepalive 216 + if ((requires_keepalive 217 217 && matches!( 218 218 strategy, 219 219 ProtocolKeepaliveStrategy::HardwareRequiredRepeatLastPacketStrategy ··· 221 221 || matches!( 222 222 strategy, 223 223 ProtocolKeepaliveStrategy::RepeatLastPacketStrategyWithTiming(_) 224 - ) 225 - { 226 - if let Err(e) = device.handle_stop_device_cmd().await { 224 + )) 225 + && let Err(e) = device.handle_stop_device_cmd().await { 227 226 return Err(ButtplugDeviceError::DeviceConnectionError(format!( 228 227 "Error setting up keepalive: {e}" 229 228 ))); 230 229 } 231 - } 232 230 233 231 Ok(device) 234 232 } ··· 265 263 // TODO This needs to throw system error messages 266 264 let send_hw_cmd = async |command| { 267 265 let _ = hardware.parse_message(&command).await; 268 - if (requires_keepalive 266 + if ((requires_keepalive 269 267 && matches!( 270 268 strategy, 271 269 ProtocolKeepaliveStrategy::HardwareRequiredRepeatLastPacketStrategy ··· 273 271 || matches!( 274 272 strategy, 275 273 ProtocolKeepaliveStrategy::RepeatLastPacketStrategyWithTiming(_) 276 - ) 277 - { 278 - if let HardwareCommand::Write(command) = command { 274 + )) 275 + && let HardwareCommand::Write(command) = command { 279 276 *keepalive_packet.lock().await = Some(command); 280 - } 281 - }; 277 + }; 282 278 }; 283 279 loop { 284 280 let requires_keepalive = hardware.requires_keepalive(); ··· 393 389 } 394 390 } 395 391 ProtocolKeepaliveStrategy::HardwareRequiredRepeatLastPacketStrategy => { 396 - if let Some(packet) = keepalive_packet { 397 - if let Err(e) = hardware.write_value(&packet).await { 392 + if let Some(packet) = keepalive_packet 393 + && let Err(e) = hardware.write_value(&packet).await { 398 394 warn!("Error writing keepalive packet: {:?}", e); 399 395 break; 400 396 } 401 - } 402 397 } 403 398 } 404 399 } ··· 470 465 hardware, 471 466 definition: definition.clone(), 472 467 // Generating legacy attributes is cheap, just do it right when we create the device. 473 - legacy_attributes: ServerDeviceAttributes::new(&definition.features()), 468 + legacy_attributes: ServerDeviceAttributes::new(definition.features()), 474 469 last_output_command: DashMap::new(), 475 470 stop_commands, 476 471 internal_hw_msg_sender, ··· 567 562 } 568 563 569 564 fn handle_outputcmd_v4(&self, msg: &CheckedOutputCmdV4) -> ButtplugServerResultFuture { 570 - if let Some(last_msg) = self.last_output_command.get(&msg.feature_id()) { 571 - if *last_msg == *msg { 565 + if let Some(last_msg) = self.last_output_command.get(&msg.feature_id()) 566 + && *last_msg == *msg { 572 567 trace!("No commands generated for incoming device packet, skipping and returning success."); 573 568 return future::ready(Ok(message::OkV0::default().into())).boxed(); 574 569 } 575 - } 576 570 self 577 571 .last_output_command 578 572 .insert(msg.feature_id(), msg.clone());
+2 -2
crates/buttplug_server/src/device/server_device_manager_event_loop.rs
··· 236 236 address = tracing::field::display(address.clone()) 237 237 ); 238 238 239 - let _ = async_manager::spawn(async move { 239 + async_manager::spawn(async move { 240 240 match ServerDevice::build(device_config_manager, creator, protocol_specializers).await { 241 241 Ok(device) => { 242 242 if device_event_sender_clone ··· 324 324 // them know a device has been added. 325 325 if self 326 326 .server_sender 327 - .send(device_update_message.into()) 327 + .send(device_update_message) 328 328 .is_err() 329 329 { 330 330 debug!("Server not currently available, dropping Device Added event.");
+1 -1
crates/buttplug_server/src/message/v2/battery_level_cmd.rs
··· 76 76 .features() 77 77 .iter() 78 78 .enumerate() 79 - .find(|(_, p)| p.input().as_ref().map_or(false, |x| x.battery().is_some())) 79 + .find(|(_, p)| p.input().as_ref().is_some_and(|x| x.battery().is_some())) 80 80 .expect("Already found matching battery feature, can unwrap this.") 81 81 .0; 82 82
+20 -30
crates/buttplug_server/src/message/v3/client_device_message_attributes.rs
··· 257 257 }; 258 258 actuator_vec.push(attrs) 259 259 }; 260 - output_map 260 + if let Some(x) = output_map 261 261 .constrict() 262 - .as_ref() 263 - .map(|x| create_actuator(OutputType::Constrict, x)); 264 - output_map 262 + .as_ref() { create_actuator(OutputType::Constrict, x) } 263 + if let Some(x) = output_map 265 264 .heater() 266 - .as_ref() 267 - .map(|x| create_actuator(OutputType::Heater, x)); 268 - output_map 265 + .as_ref() { create_actuator(OutputType::Heater, x) } 266 + if let Some(x) = output_map 269 267 .led() 270 - .as_ref() 271 - .map(|x| create_actuator(OutputType::Led, x)); 272 - output_map 268 + .as_ref() { create_actuator(OutputType::Led, x) } 269 + if let Some(x) = output_map 273 270 .oscillate() 274 - .as_ref() 275 - .map(|x| create_actuator(OutputType::Oscillate, x)); 276 - output_map 271 + .as_ref() { create_actuator(OutputType::Oscillate, x) } 272 + if let Some(x) = output_map 277 273 .position() 278 - .as_ref() 279 - .map(|x| create_actuator(OutputType::Position, x)); 280 - output_map 274 + .as_ref() { create_actuator(OutputType::Position, x) } 275 + if let Some(x) = output_map 281 276 .rotate() 282 - .as_ref() 283 - .map(|x| create_actuator(OutputType::Rotate, x)); 284 - output_map 277 + .as_ref() { create_actuator(OutputType::Rotate, x) } 278 + if let Some(x) = output_map 285 279 .spray() 286 - .as_ref() 287 - .map(|x| create_actuator(OutputType::Spray, x)); 288 - output_map 280 + .as_ref() { create_actuator(OutputType::Spray, x) } 281 + if let Some(x) = output_map 289 282 .vibrate() 290 - .as_ref() 291 - .map(|x| create_actuator(OutputType::Vibrate, x)); 283 + .as_ref() { create_actuator(OutputType::Vibrate, x) } 292 284 } 293 285 actuator_vec 294 286 }) ··· 300 292 .iter() 301 293 .flat_map(|feature| { 302 294 let mut actuator_vec = vec![]; 303 - if let Some(output_map) = feature.output() { 304 - if let Some(actuator) = output_map.rotate_with_direction() { 295 + if let Some(output_map) = feature.output() 296 + && let Some(actuator) = output_map.rotate_with_direction() { 305 297 let actuator_type = OutputType::Rotate; 306 298 let attrs = ClientGenericDeviceMessageAttributesV3 { 307 299 feature_descriptor: feature.description().to_owned(), ··· 311 303 }; 312 304 actuator_vec.push(attrs) 313 305 } 314 - } 315 306 actuator_vec 316 307 }) 317 308 .collect(); ··· 320 311 .iter() 321 312 .flat_map(|feature| { 322 313 let mut actuator_vec = vec![]; 323 - if let Some(output_map) = feature.output() { 324 - if let Some(actuator) = output_map.position_with_duration() { 314 + if let Some(output_map) = feature.output() 315 + && let Some(actuator) = output_map.position_with_duration() { 325 316 let actuator_type = OutputType::Position; 326 317 let attrs = ClientGenericDeviceMessageAttributesV3 { 327 318 feature_descriptor: feature.description().to_owned(), ··· 331 322 }; 332 323 actuator_vec.push(attrs) 333 324 } 334 - } 335 325 actuator_vec 336 326 }) 337 327 .collect();
+1 -1
crates/buttplug_server/src/message/v3/sensor_read_cmd.rs
··· 81 81 .features() 82 82 .iter() 83 83 .enumerate() 84 - .find(|(_, p)| p.input().as_ref().map_or(false, |x| x.battery().is_some())) 84 + .find(|(_, p)| p.input().as_ref().is_some_and(|x| x.battery().is_some())) 85 85 { 86 86 Ok(CheckedInputCmdV4::new( 87 87 msg.device_index(),
+22 -33
crates/buttplug_server/src/message/v3/server_device_message_attributes.rs
··· 72 72 }; 73 73 // TODO oh come on just make a fucking iterator here. At least, once we figure out the 74 74 // unifying trait we can use to make an iterator on this. 75 - output_map 75 + if let Some(attr) = output_map 76 76 .constrict() 77 - .as_ref() 78 - .map(|attr| create_attribute(OutputType::Constrict, attr.value().step_count())); 79 - output_map 77 + .as_ref() { create_attribute(OutputType::Constrict, attr.value().step_count()) } 78 + if let Some(attr) = output_map 80 79 .oscillate() 81 - .as_ref() 82 - .map(|attr| create_attribute(OutputType::Oscillate, attr.value().step_count())); 83 - output_map 80 + .as_ref() { create_attribute(OutputType::Oscillate, attr.value().step_count()) } 81 + if let Some(attr) = output_map 84 82 .position() 85 - .as_ref() 86 - .map(|attr| create_attribute(OutputType::Position, attr.position().step_count())); 87 - output_map 83 + .as_ref() { create_attribute(OutputType::Position, attr.position().step_count()) } 84 + if let Some(attr) = output_map 88 85 .rotate() 89 - .as_ref() 90 - .map(|attr| create_attribute(OutputType::Rotate, attr.value().step_count())); 91 - output_map 86 + .as_ref() { create_attribute(OutputType::Rotate, attr.value().step_count()) } 87 + if let Some(attr) = output_map 92 88 .heater() 93 - .as_ref() 94 - .map(|attr| create_attribute(OutputType::Heater, attr.value().step_count())); 95 - output_map 89 + .as_ref() { create_attribute(OutputType::Heater, attr.value().step_count()) } 90 + if let Some(attr) = output_map 96 91 .led() 97 - .as_ref() 98 - .map(|attr| create_attribute(OutputType::Led, attr.value().step_count())); 99 - output_map 92 + .as_ref() { create_attribute(OutputType::Led, attr.value().step_count()) } 93 + if let Some(attr) = output_map 100 94 .vibrate() 101 - .as_ref() 102 - .map(|attr| create_attribute(OutputType::Vibrate, attr.value().step_count())); 103 - output_map 95 + .as_ref() { create_attribute(OutputType::Vibrate, attr.value().step_count()) } 96 + if let Some(attr) = output_map 104 97 .spray() 105 - .as_ref() 106 - .map(|attr| create_attribute(OutputType::Spray, attr.value().step_count())); 98 + .as_ref() { create_attribute(OutputType::Spray, attr.value().step_count()) } 107 99 } 108 100 actuator_vec 109 101 }) ··· 115 107 .iter() 116 108 .flat_map(|feature| { 117 109 let mut actuator_vec = vec![]; 118 - if let Some(output_map) = feature.output() { 119 - if let Some(actuator) = output_map.rotate_with_direction() { 110 + if let Some(output_map) = feature.output() 111 + && let Some(actuator) = output_map.rotate_with_direction() { 120 112 let actuator_type = OutputType::Rotate; 121 113 let step_count = actuator.value().step_count(); 122 114 let attrs = ServerGenericDeviceMessageAttributesV3 { ··· 128 120 }; 129 121 actuator_vec.push(attrs) 130 122 } 131 - } 132 123 actuator_vec 133 124 }) 134 125 .collect(); ··· 137 128 .iter() 138 129 .flat_map(|feature| { 139 130 let mut actuator_vec = vec![]; 140 - if let Some(output_map) = feature.output() { 141 - if let Some(actuator) = output_map.position_with_duration() { 131 + if let Some(output_map) = feature.output() 132 + && let Some(actuator) = output_map.position_with_duration() { 142 133 let actuator_type = OutputType::Position; 143 134 let step_count = actuator.position().step_count(); 144 135 let attrs = ServerGenericDeviceMessageAttributesV3 { ··· 150 141 }; 151 142 actuator_vec.push(attrs) 152 143 } 153 - } 154 144 actuator_vec 155 145 }) 156 146 .collect(); ··· 160 150 .iter() 161 151 .map(|feature| { 162 152 let mut sensor_vec = vec![]; 163 - if let Some(sensor_map) = feature.input() { 164 - if let Some(battery) = sensor_map.battery() { 153 + if let Some(sensor_map) = feature.input() 154 + && let Some(battery) = sensor_map.battery() { 165 155 // Only convert Battery backwards. Other sensors weren't really built for v3 and we 166 156 // never recommended using them or implemented much for them. 167 157 sensor_vec.push(ServerSensorDeviceMessageAttributesV3 { ··· 172 162 index: 0, 173 163 }); 174 164 } 175 - } 176 165 sensor_vec 177 166 }) 178 167 .flatten()
+1 -1
crates/buttplug_server/src/message/v4/checked_output_cmd.rs
··· 72 72 device_index, 73 73 feature_index, 74 74 feature_id, 75 - output_command: output_command, 75 + output_command, 76 76 } 77 77 } 78 78 }
+1 -1
crates/buttplug_server/src/message/v4/checked_output_vec_cmd.rs
··· 88 88 feature 89 89 .output() 90 90 .as_ref() 91 - .map_or(false, |x| x.contains(OutputType::Vibrate)) 91 + .is_some_and(|x| x.contains(OutputType::Vibrate)) 92 92 }) 93 93 .peekable(); 94 94
+1 -1
crates/buttplug_server/src/server.rs
··· 175 175 } 176 176 177 177 /// Disconnects the server from a client, if it is connected. 178 - pub fn disconnect(&self) -> BoxFuture<Result<(), message::ErrorV0>> { 178 + pub fn disconnect(&self) -> BoxFuture<'_, Result<(), message::ErrorV0>> { 179 179 debug!("Buttplug Server {} disconnect requested", self.server_name); 180 180 let ping_timer = self.ping_timer.clone(); 181 181 // As long as StopScanning/StopAllDevices aren't changed across message specs, we can inject
+10 -10
crates/buttplug_server/src/server_message_conversion.rs
··· 94 94 return ButtplugServerMessageVariant::V1(da1.into()); 95 95 } 96 96 let da0 = DeviceAddedV0::from(da1); 97 - return ButtplugServerMessageVariant::V0(ButtplugServerMessageV0::DeviceAdded(da0)); 97 + ButtplugServerMessageVariant::V0(ButtplugServerMessageV0::DeviceAdded(da0)) 98 98 } else { 99 99 // Device Removed 100 100 let disconnected_indexes: Vec<u32> = self ··· 106 106 self.device_indexes.remove(&disconnected_indexes[0]); 107 107 match version { 108 108 ButtplugMessageSpecVersion::Version0 => { 109 - return ButtplugServerMessageVariant::V0(ButtplugServerMessageV0::DeviceRemoved( 109 + ButtplugServerMessageVariant::V0(ButtplugServerMessageV0::DeviceRemoved( 110 110 DeviceRemovedV0::new(disconnected_indexes[0]), 111 - )); 111 + )) 112 112 } 113 113 ButtplugMessageSpecVersion::Version1 => { 114 - return ButtplugServerMessageVariant::V1( 114 + ButtplugServerMessageVariant::V1( 115 115 DeviceRemovedV0::new(disconnected_indexes[0]).into(), 116 - ); 116 + ) 117 117 } 118 118 ButtplugMessageSpecVersion::Version2 => { 119 - return ButtplugServerMessageVariant::V2( 119 + ButtplugServerMessageVariant::V2( 120 120 DeviceRemovedV0::new(disconnected_indexes[0]).into(), 121 - ); 121 + ) 122 122 } 123 123 ButtplugMessageSpecVersion::Version3 => { 124 - return ButtplugServerMessageVariant::V3( 124 + ButtplugServerMessageVariant::V3( 125 125 DeviceRemovedV0::new(disconnected_indexes[0]).into(), 126 - ); 126 + ) 127 127 } 128 128 ButtplugMessageSpecVersion::Version4 => { 129 - return ButtplugServerMessageVariant::V4(list.clone().into()); 129 + ButtplugServerMessageVariant::V4(list.clone().into()) 130 130 } 131 131 } 132 132 }
-1
crates/buttplug_server_device_config/build.rs
··· 3 3 use buttplug_core::util::json::JSONValidator; 4 4 use serde::{Deserialize, Serialize}; 5 5 use serde_json::{self, Value}; 6 - use serde_yaml; 7 6 8 7 const VERSION_FILE: &str = "./device-config-v4/version.yaml"; 9 8 const OUTPUT_FILE: &str = "./build-config/buttplug-device-config-v4.json";
+8 -8
crates/buttplug_server_device_config/src/device_config_file/device.rs
··· 36 36 } 37 37 } 38 38 39 - impl Into<ServerDeviceDefinition> for ConfigBaseDeviceDefinition { 40 - fn into(self) -> ServerDeviceDefinition { 41 - let mut builder = ServerDeviceDefinitionBuilder::new(&self.name, &self.id); 42 - if let Some(variant) = self.protocol_variant { 39 + impl From<ConfigBaseDeviceDefinition> for ServerDeviceDefinition { 40 + fn from(val: ConfigBaseDeviceDefinition) -> Self { 41 + let mut builder = ServerDeviceDefinitionBuilder::new(&val.name, &val.id); 42 + if let Some(variant) = val.protocol_variant { 43 43 builder.protocol_variant(&variant); 44 44 } 45 - if let Some(gap) = self.message_gap_ms { 45 + if let Some(gap) = val.message_gap_ms { 46 46 builder.message_gap_ms(gap); 47 47 } 48 - if let Some(features) = self.features { 48 + if let Some(features) = val.features { 49 49 for feature in features { 50 50 builder.add_feature(&feature.into()); 51 51 } ··· 79 79 allow: value.allow(), 80 80 deny: value.deny(), 81 81 index: value.index(), 82 - message_gap_ms: value.message_gap_ms().clone(), 82 + message_gap_ms: value.message_gap_ms(), 83 83 } 84 84 } 85 85 } ··· 104 104 &self, 105 105 base: &ServerDeviceDefinition, 106 106 ) -> Result<ServerDeviceDefinition, ButtplugDeviceConfigError> { 107 - let mut builder = ServerDeviceDefinitionBuilder::from_base(&base, self.id); 107 + let mut builder = ServerDeviceDefinitionBuilder::from_base(base, self.id); 108 108 if let Some(display_name) = &self.user_config.display_name { 109 109 builder.display_name(display_name); 110 110 }
+42 -50
crates/buttplug_server_device_config/src/device_config_file/feature.rs
··· 34 34 value: RangeInclusive<i32>, 35 35 } 36 36 37 - impl Into<ServerDeviceFeatureOutputValueProperties> for BaseDeviceFeatureOutputValueProperties { 38 - fn into(self) -> ServerDeviceFeatureOutputValueProperties { 39 - ServerDeviceFeatureOutputValueProperties::new(&self.value.into(), false) 37 + impl From<BaseDeviceFeatureOutputValueProperties> for ServerDeviceFeatureOutputValueProperties { 38 + fn from(val: BaseDeviceFeatureOutputValueProperties) -> Self { 39 + ServerDeviceFeatureOutputValueProperties::new(&val.value.into(), false) 40 40 } 41 41 } 42 42 ··· 45 45 value: RangeInclusive<i32>, 46 46 } 47 47 48 - impl Into<ServerDeviceFeatureOutputPositionProperties> 49 - for BaseDeviceFeatureOutputPositionProperties 48 + impl From<BaseDeviceFeatureOutputPositionProperties> 49 + for ServerDeviceFeatureOutputPositionProperties 50 50 { 51 - fn into(self) -> ServerDeviceFeatureOutputPositionProperties { 52 - ServerDeviceFeatureOutputPositionProperties::new(&self.value.into(), false, false) 51 + fn from(val: BaseDeviceFeatureOutputPositionProperties) -> Self { 52 + ServerDeviceFeatureOutputPositionProperties::new(&val.value.into(), false, false) 53 53 } 54 54 } 55 55 ··· 59 59 duration: RangeInclusive<i32>, 60 60 } 61 61 62 - impl Into<ServerDeviceFeatureOutputPositionWithDurationProperties> 63 - for BaseDeviceFeatureOutputPositionWithDurationProperties 62 + impl From<BaseDeviceFeatureOutputPositionWithDurationProperties> 63 + for ServerDeviceFeatureOutputPositionWithDurationProperties 64 64 { 65 - fn into(self) -> ServerDeviceFeatureOutputPositionWithDurationProperties { 65 + fn from(val: BaseDeviceFeatureOutputPositionWithDurationProperties) -> Self { 66 66 ServerDeviceFeatureOutputPositionWithDurationProperties::new( 67 - &self.position.into(), 68 - &self.duration.into(), 67 + &val.position.into(), 68 + &val.duration.into(), 69 69 false, 70 70 false, 71 71 ) ··· 96 96 spray: Option<BaseDeviceFeatureOutputValueProperties>, 97 97 } 98 98 99 - impl Into<ServerDeviceFeatureOutput> for BaseDeviceFeatureOutput { 100 - fn into(self) -> ServerDeviceFeatureOutput { 99 + impl From<BaseDeviceFeatureOutput> for ServerDeviceFeatureOutput { 100 + fn from(val: BaseDeviceFeatureOutput) -> Self { 101 101 let mut output = ServerDeviceFeatureOutput::default(); 102 - if let Some(vibrate) = self.vibrate { 102 + if let Some(vibrate) = val.vibrate { 103 103 output.set_vibrate(Some(vibrate.into())); 104 104 } 105 - if let Some(rotate) = self.rotate { 105 + if let Some(rotate) = val.rotate { 106 106 output.set_rotate(Some(rotate.into())); 107 107 } 108 - if let Some(rotate_with_direction) = self.rotate_with_direction { 108 + if let Some(rotate_with_direction) = val.rotate_with_direction { 109 109 output.set_rotate_with_direction(Some(rotate_with_direction.into())); 110 110 } 111 - if let Some(oscillate) = self.oscillate { 111 + if let Some(oscillate) = val.oscillate { 112 112 output.set_oscillate(Some(oscillate.into())); 113 113 } 114 - if let Some(constrict) = self.constrict { 114 + if let Some(constrict) = val.constrict { 115 115 output.set_constrict(Some(constrict.into())); 116 116 } 117 - if let Some(heater) = self.heater { 117 + if let Some(heater) = val.heater { 118 118 output.set_heater(Some(heater.into())); 119 119 } 120 - if let Some(led) = self.led { 120 + if let Some(led) = val.led { 121 121 output.set_led(Some(led.into())); 122 122 } 123 - if let Some(position) = self.position { 123 + if let Some(position) = val.position { 124 124 output.set_position(Some(position.into())); 125 125 } 126 - if let Some(position_with_duration) = self.position_with_duration { 126 + if let Some(position_with_duration) = val.position_with_duration { 127 127 output.set_position_with_duration(Some(position_with_duration.into())); 128 128 } 129 - if let Some(spray) = self.spray { 129 + if let Some(spray) = val.spray { 130 130 output.set_spray(Some(spray.into())); 131 131 } 132 132 output ··· 380 380 } 381 381 } 382 382 383 - impl Into<ServerDeviceFeatureInputProperties> for DeviceFeatureInputProperties { 384 - fn into(self) -> ServerDeviceFeatureInputProperties { 385 - ServerDeviceFeatureInputProperties::new(&self.value_range, &self.input_commands) 383 + impl From<DeviceFeatureInputProperties> for ServerDeviceFeatureInputProperties { 384 + fn from(val: DeviceFeatureInputProperties) -> Self { 385 + ServerDeviceFeatureInputProperties::new(&val.value_range, &val.input_commands) 386 386 } 387 387 } 388 388 ··· 395 395 button: Option<DeviceFeatureInputProperties>, 396 396 } 397 397 398 - impl Into<ServerDeviceFeatureInput> for DeviceFeatureInput { 399 - fn into(self) -> ServerDeviceFeatureInput { 398 + impl From<DeviceFeatureInput> for ServerDeviceFeatureInput { 399 + fn from(val: DeviceFeatureInput) -> Self { 400 400 let mut input = ServerDeviceFeatureInput::default(); 401 - if let Some(battery) = self.battery { 401 + if let Some(battery) = val.battery { 402 402 input.set_battery(Some(battery.into())); 403 403 } 404 - if let Some(rssi) = self.rssi { 404 + if let Some(rssi) = val.rssi { 405 405 input.set_rssi(Some(rssi.into())); 406 406 } 407 - if let Some(pressure) = self.pressure { 407 + if let Some(pressure) = val.pressure { 408 408 input.set_pressure(Some(pressure.into())); 409 409 } 410 - if let Some(button) = self.button { 410 + if let Some(button) = val.button { 411 411 input.set_button(Some(button.into())); 412 412 } 413 413 input ··· 432 432 feature_settings: BaseFeatureSettings, 433 433 } 434 434 435 - impl Into<ServerDeviceFeature> for ConfigBaseDeviceFeature { 436 - fn into(self) -> ServerDeviceFeature { 435 + impl From<ConfigBaseDeviceFeature> for ServerDeviceFeature { 436 + fn from(val: ConfigBaseDeviceFeature) -> Self { 437 437 // This isn't resolving correctly using .and_then, so having to do it the long way? 438 - let output: Option<ServerDeviceFeatureOutput> = if let Some(o) = self.output { 439 - Some(o.into()) 440 - } else { 441 - None 442 - }; 443 - let input: Option<ServerDeviceFeatureInput> = if let Some(i) = self.input { 444 - Some(i.into()) 445 - } else { 446 - None 447 - }; 438 + let output: Option<ServerDeviceFeatureOutput> = val.output.map(|o| o.into()); 439 + let input: Option<ServerDeviceFeatureInput> = val.input.map(|i| i.into()); 448 440 ServerDeviceFeature::new( 449 - &self.description, 450 - self.id, 441 + &val.description, 442 + val.id, 451 443 None, 452 - self.feature_settings.alt_protocol_index, 444 + val.feature_settings.alt_protocol_index, 453 445 &output, 454 446 &input, 455 447 ) ··· 474 466 ) -> Result<ServerDeviceFeature, ButtplugDeviceConfigError> { 475 467 let output = if let Some(o) = &self.output { 476 468 if let Some(base) = base_feature.output() { 477 - Some(o.with_base_output(&base)?) 469 + Some(o.with_base_output(base)?) 478 470 } else { 479 471 None 480 472 } ··· 482 474 None 483 475 }; 484 476 Ok(ServerDeviceFeature::new( 485 - &base_feature.description(), 477 + base_feature.description(), 486 478 self.id, 487 479 Some(self.base_id), 488 480 base_feature.alt_protocol_index(),
+4 -6
crates/buttplug_server_device_config/src/device_config_file/mod.rs
··· 31 31 Serializer, 32 32 ser::{self, SerializeSeq}, 33 33 }; 34 - use std::{collections::HashMap, fmt::Display, ops::RangeInclusive}; 34 + use std::{fmt::Display, ops::RangeInclusive}; 35 35 36 36 pub static DEVICE_CONFIGURATION_JSON: &str = 37 37 include_str!("../../build-config/buttplug-device-config-v4.json"); ··· 146 146 147 147 for (protocol_name, protocol_def) in main_config.protocols().clone().unwrap_or_default() { 148 148 if let Some(specifiers) = protocol_def.communication() { 149 - dcm_builder.communication_specifier(&protocol_name, &specifiers); 149 + dcm_builder.communication_specifier(&protocol_name, specifiers); 150 150 } 151 151 152 152 let mut default = None; ··· 199 199 200 200 for (protocol_name, protocol_def) in user_config.protocols().clone().unwrap_or_default() { 201 201 if let Some(specifiers) = protocol_def.communication() { 202 - dcm_builder.user_communication_specifier(&protocol_name, &specifiers); 202 + dcm_builder.user_communication_specifier(&protocol_name, specifiers); 203 203 } 204 204 205 205 // Defaults aren't valid in user config files. All we can do is create new configurations with ··· 227 227 if let Ok(user_config) = user_device_config_pair 228 228 .config() 229 229 .build_from_base_definition(base_config) 230 - { 231 - if let Err(e) = 230 + && let Err(e) = 232 231 dcm_builder.user_device_definition(user_device_config_pair.identifier(), &user_config) 233 232 { 234 233 error!( ··· 236 235 e, user_config 237 236 ) 238 237 } 239 - } 240 238 } else { 241 239 error!( 242 240 "Device identifier {:?} does not have a match base identifier that matches anything in the base config, removing from database.",
-1
crates/buttplug_server_device_config/src/device_config_file/protocol.rs
··· 1 - use std::collections::HashMap; 2 1 3 2 use getset::{Getters, MutGetters, Setters}; 4 3 use serde::{Deserialize, Serialize};
+1 -2
crates/buttplug_server_device_config/src/device_config_manager.rs
··· 70 70 if self 71 71 .base_device_definitions 72 72 .iter() 73 - .find(|(_, x)| x.id() == device_definition.base_id().unwrap_or_default()) 74 - .is_some() 73 + .any(|(_, x)| x.id() == device_definition.base_id().unwrap_or_default()) 75 74 { 76 75 self 77 76 .user_device_definitions
+1 -1
crates/buttplug_server_device_config/src/device_definitions.rs
··· 36 36 Self { 37 37 def: ServerDeviceDefinition { 38 38 name: name.to_owned(), 39 - id: id.clone(), 39 + id: *id, 40 40 base_id: None, 41 41 protocol_variant: None, 42 42 message_gap_ms: None,
+54 -58
crates/buttplug_server_device_config/src/server_device_feature.rs
··· 75 75 if let Some(user) = user { 76 76 if user.is_empty() { 77 77 Err(ButtplugDeviceConfigError::InvalidUserRange) 78 - } else { 79 - if *user.start() < *truncated_base.start() 80 - || *user.end() > *truncated_base.end() 81 - || *user.start() > *truncated_base.end() 82 - || *user.end() < *truncated_base.start() 83 - { 84 - Err(ButtplugDeviceConfigError::InvalidUserRange) 85 - } else { 86 - Ok(Self { 87 - base: (*base).clone(), 88 - internal_base: truncated_base, 89 - user: Some((*user).clone()), 90 - }) 91 - } 92 - } 93 - } else { 94 - if base.is_empty() { 95 - Err(ButtplugDeviceConfigError::BaseRangeRequired) 78 + } else if *user.start() < *truncated_base.start() 79 + || *user.end() > *truncated_base.end() 80 + || *user.start() > *truncated_base.end() 81 + || *user.end() < *truncated_base.start() 82 + { 83 + Err(ButtplugDeviceConfigError::InvalidUserRange) 96 84 } else { 97 85 Ok(Self { 98 86 base: (*base).clone(), 99 87 internal_base: truncated_base, 100 - user: None, 88 + user: Some((*user).clone()), 101 89 }) 102 90 } 91 + } else if base.is_empty() { 92 + Err(ButtplugDeviceConfigError::BaseRangeRequired) 93 + } else { 94 + Ok(Self { 95 + base: (*base).clone(), 96 + internal_base: truncated_base, 97 + user: None, 98 + }) 103 99 } 104 100 } 105 101 } ··· 121 117 } 122 118 123 119 pub fn calculate_scaled_float(&self, value: f64) -> Result<i32, ButtplugDeviceConfigError> { 124 - if value > 1.0 || value < 0.0 { 120 + if !(0.0..=1.0).contains(&value) { 125 121 Err(ButtplugDeviceConfigError::InvalidFloatConversion(value)) 126 122 } else { 127 123 let value = if value < 0.000001 { 0f64 } else { value }; ··· 137 133 } else { 138 134 self.value.internal_base() 139 135 }; 140 - let current_value = value.abs() as u32; 136 + let current_value = value.unsigned_abs(); 141 137 let mult = if value < 0 { -1 } else { 1 }; 142 138 if value > 0 && range.contains(&(range.start() + current_value)) { 143 139 Ok((range.start() + current_value) as i32 * mult) ··· 145 141 Ok(0) 146 142 } else { 147 143 Err(ButtplugDeviceConfigError::InvalidOutputValue( 148 - value as i32, 144 + value, 149 145 format!("{:?}", range), 150 146 )) 151 147 } 152 148 } 153 149 } 154 150 155 - impl Into<DeviceFeatureOutputValueProperties> for &ServerDeviceFeatureOutputValueProperties { 156 - fn into(self) -> DeviceFeatureOutputValueProperties { 157 - DeviceFeatureOutputValueProperties::new(&self.value().step_limit()) 151 + impl From<&ServerDeviceFeatureOutputValueProperties> for DeviceFeatureOutputValueProperties { 152 + fn from(val: &ServerDeviceFeatureOutputValueProperties) -> Self { 153 + DeviceFeatureOutputValueProperties::new(&val.value().step_limit()) 158 154 } 159 155 } 160 156 ··· 178 174 } 179 175 180 176 pub fn calculate_scaled_float(&self, value: f64) -> Result<i32, ButtplugDeviceConfigError> { 181 - if value > 1.0 || value < 0.0 { 177 + if !(0.0..=1.0).contains(&value) { 182 178 Err(ButtplugDeviceConfigError::InvalidFloatConversion(value)) 183 179 } else { 184 180 self ··· 211 207 } 212 208 } 213 209 214 - impl Into<DeviceFeatureOutputValueProperties> for &ServerDeviceFeatureOutputPositionProperties { 215 - fn into(self) -> DeviceFeatureOutputValueProperties { 216 - DeviceFeatureOutputValueProperties::new(&self.position().step_limit()) 210 + impl From<&ServerDeviceFeatureOutputPositionProperties> for DeviceFeatureOutputValueProperties { 211 + fn from(val: &ServerDeviceFeatureOutputPositionProperties) -> Self { 212 + DeviceFeatureOutputValueProperties::new(&val.position().step_limit()) 217 213 } 218 214 } 219 215 ··· 272 268 } 273 269 } 274 270 275 - impl Into<DeviceFeatureOutputPositionWithDurationProperties> 276 - for &ServerDeviceFeatureOutputPositionWithDurationProperties 271 + impl From<&ServerDeviceFeatureOutputPositionWithDurationProperties> 272 + for DeviceFeatureOutputPositionWithDurationProperties 277 273 { 278 - fn into(self) -> DeviceFeatureOutputPositionWithDurationProperties { 274 + fn from(val: &ServerDeviceFeatureOutputPositionWithDurationProperties) -> Self { 279 275 DeviceFeatureOutputPositionWithDurationProperties::new( 280 - &self.position().step_limit(), 281 - &self.duration().step_limit(), 276 + &val.position().step_limit(), 277 + &val.duration().step_limit(), 282 278 ) 283 279 } 284 280 } ··· 429 425 ), 430 426 OutputType::Position => self.position.as_ref().map_or( 431 427 Err(ButtplugDeviceConfigError::InvalidOutput(output_type)), 432 - |x| x.calculate_scaled_float(value).map(|x| x as i32), 428 + |x| x.calculate_scaled_float(value), 433 429 ), 434 430 OutputType::PositionWithDuration => self.position_with_duration.as_ref().map_or( 435 431 Err(ButtplugDeviceConfigError::InvalidOutput(output_type)), ··· 456 452 } 457 453 } 458 454 459 - impl Into<DeviceFeatureOutput> for ServerDeviceFeatureOutput { 460 - fn into(self) -> DeviceFeatureOutput { 455 + impl From<ServerDeviceFeatureOutput> for DeviceFeatureOutput { 456 + fn from(val: ServerDeviceFeatureOutput) -> Self { 461 457 let mut builder = DeviceFeatureOutputBuilder::default(); 462 - self.vibrate.as_ref().map(|x| builder.vibrate(x.into())); 463 - self.rotate.as_ref().map(|x| builder.rotate(x.into())); 464 - self 458 + val.vibrate.as_ref().map(|x| builder.vibrate(x.into())); 459 + val.rotate.as_ref().map(|x| builder.rotate(x.into())); 460 + val 465 461 .rotate_with_direction 466 462 .as_ref() 467 463 .map(|x| builder.rotate_with_direction(x.into())); 468 - self.oscillate.as_ref().map(|x| builder.oscillate(x.into())); 469 - self.constrict.as_ref().map(|x| builder.constrict(x.into())); 470 - self.heater.as_ref().map(|x| builder.heater(x.into())); 471 - self.led.as_ref().map(|x| builder.led(x.into())); 472 - self.position.as_ref().map(|x| builder.position(x.into())); 473 - self 464 + val.oscillate.as_ref().map(|x| builder.oscillate(x.into())); 465 + val.constrict.as_ref().map(|x| builder.constrict(x.into())); 466 + val.heater.as_ref().map(|x| builder.heater(x.into())); 467 + val.led.as_ref().map(|x| builder.led(x.into())); 468 + val.position.as_ref().map(|x| builder.position(x.into())); 469 + val 474 470 .position_with_duration 475 471 .as_ref() 476 472 .map(|x| builder.position_with_duration(x.into())); 477 - self.spray.as_ref().map(|x| builder.spray(x.into())); 473 + val.spray.as_ref().map(|x| builder.spray(x.into())); 478 474 builder.build().expect("Infallible") 479 475 } 480 476 } ··· 498 494 } 499 495 } 500 496 501 - impl Into<DeviceFeatureInputProperties> for &ServerDeviceFeatureInputProperties { 502 - fn into(self) -> DeviceFeatureInputProperties { 503 - DeviceFeatureInputProperties::new(&self.value_range, &self.input_commands) 497 + impl From<&ServerDeviceFeatureInputProperties> for DeviceFeatureInputProperties { 498 + fn from(val: &ServerDeviceFeatureInputProperties) -> Self { 499 + DeviceFeatureInputProperties::new(&val.value_range, &val.input_commands) 504 500 } 505 501 } 506 502 ··· 525 521 } 526 522 } 527 523 528 - impl Into<DeviceFeatureInput> for ServerDeviceFeatureInput { 529 - fn into(self) -> DeviceFeatureInput { 524 + impl From<ServerDeviceFeatureInput> for DeviceFeatureInput { 525 + fn from(val: ServerDeviceFeatureInput) -> Self { 530 526 let mut builder = DeviceFeatureInputBuilder::default(); 531 - self.battery.as_ref().map(|x| builder.battery(x.into())); 532 - self.rssi.as_ref().map(|x| builder.rssi(x.into())); 533 - self.pressure.as_ref().map(|x| builder.pressure(x.into())); 534 - self.button.as_ref().map(|x| builder.button(x.into())); 527 + val.battery.as_ref().map(|x| builder.battery(x.into())); 528 + val.rssi.as_ref().map(|x| builder.rssi(x.into())); 529 + val.pressure.as_ref().map(|x| builder.pressure(x.into())); 530 + val.button.as_ref().map(|x| builder.button(x.into())); 535 531 builder.build().expect("Infallible") 536 532 } 537 533 } ··· 584 580 Ok(DeviceFeature::new( 585 581 index, 586 582 self.description(), 587 - &self.output.as_ref().and_then(|x| Some(x.clone().into())), 588 - &self.input.as_ref().and_then(|x| Some(x.clone().into())), 583 + &self.output.as_ref().map(|x| x.clone().into()), 584 + &self.input.as_ref().map(|x| x.clone().into()), 589 585 )) 590 586 } 591 587 }
+5 -7
crates/buttplug_server_hwmgr_btleplug/src/btleplug_hardware.rs
··· 243 243 let event_stream_clone = event_stream.clone(); 244 244 let address = device.id(); 245 245 let name_clone = name.to_owned(); 246 - let _ = async_manager::spawn(async move { 246 + async_manager::spawn(async move { 247 247 let mut error_notification = false; 248 248 loop { 249 249 select! { ··· 279 279 } 280 280 } 281 281 adapter_event = adapter_event_stream.next() => { 282 - if let Some(CentralEvent::DeviceDisconnected(addr)) = adapter_event { 283 - if address == addr { 282 + if let Some(CentralEvent::DeviceDisconnected(addr)) = adapter_event 283 + && address == addr { 284 284 info!( 285 285 "Device {:?} disconnected", 286 286 name_clone 287 287 ); 288 - if event_stream_clone.receiver_count() != 0 { 289 - if let Err(err) = event_stream_clone 288 + if event_stream_clone.receiver_count() != 0 289 + && let Err(err) = event_stream_clone 290 290 .send(HardwareEvent::Disconnected( 291 291 format!("{address:?}") 292 292 )) { ··· 295 295 err 296 296 ); 297 297 } 298 - } 299 298 // At this point, we have nothing left to do because we can't reconnect a device 300 299 // that's been connected. Exit. 301 300 break; 302 301 } 303 - } 304 302 } 305 303 } 306 304 }
+2 -3
crates/buttplug_server_hwmgr_hid/src/hidapi_async.rs
··· 70 70 drop(req_tx); 71 71 72 72 // Wait for the reader thread to finish 73 - if let Some(jh) = guard.read_thread.take() { 74 - if jh.join().is_ok() { 73 + if let Some(jh) = guard.read_thread.take() 74 + && jh.join().is_ok() { 75 75 info!("device read thread joined") 76 76 } 77 - } 78 77 } else { 79 78 //error!("Failed to take lock on device"); 80 79 }
+1 -1
crates/buttplug_server_hwmgr_lovense_connect/src/lovense_connect_service_hardware.rs
··· 159 159 let command_url = format!( 160 160 "{}/{}", 161 161 self.http_host, 162 - std::str::from_utf8(&msg.data()) 162 + std::str::from_utf8(msg.data()) 163 163 .expect("We build this in the protocol then have to serialize to [u8], but it's a string.") 164 164 ); 165 165
+12 -18
crates/buttplug_server_hwmgr_lovense_dongle/src/lovense_dongle_state_machine.rs
··· 309 309 IncomingMessage::Dongle(device_msg) => 310 310 match device_msg.func { 311 311 LovenseDongleMessageFunc::IncomingStatus => { 312 - if let Some(incoming_data) = device_msg.data { 313 - if Some(LovenseDongleResultCode::DeviceConnectSuccess) == incoming_data.status { 312 + if let Some(incoming_data) = device_msg.data 313 + && Some(LovenseDongleResultCode::DeviceConnectSuccess) == incoming_data.status { 314 314 info!("Lovense dongle already connected to a device, registering in system."); 315 315 id = incoming_data.id; 316 316 } 317 - } 318 317 } 319 318 func => warn!("Cannot handle dongle function {:?}", func), 320 319 } ··· 348 347 match self.hub.wait_for_input().await { 349 348 IncomingMessage::Dongle(device_msg) => match device_msg.func { 350 349 LovenseDongleMessageFunc::IncomingStatus => { 351 - if let Some(incoming_data) = device_msg.data { 352 - if let Some(status) = incoming_data.status { 350 + if let Some(incoming_data) = device_msg.data 351 + && let Some(status) = incoming_data.status { 353 352 match status { 354 353 LovenseDongleResultCode::DeviceConnectSuccess => { 355 354 info!("Lovense dongle already connected to a device, registering in system."); ··· 366 365 ), 367 366 } 368 367 } 369 - } 370 368 } 371 369 LovenseDongleMessageFunc::Search => { 372 370 if let Some(result) = device_msg.result { ··· 464 462 IncomingMessage::Dongle(device_msg) => { 465 463 match device_msg.func { 466 464 LovenseDongleMessageFunc::IncomingStatus => { 467 - if let Some(incoming_data) = device_msg.data { 468 - if let Some(status) = incoming_data.status { 465 + if let Some(incoming_data) = device_msg.data 466 + && let Some(status) = incoming_data.status { 469 467 match status { 470 468 LovenseDongleResultCode::DeviceConnectSuccess => { 471 469 info!("Lovense dongle already connected to a device, registering in system."); ··· 484 482 } 485 483 } 486 484 } 487 - } 488 485 } 489 486 LovenseDongleMessageFunc::Search => { 490 487 if let Some(result) = device_msg.result { ··· 586 583 match msg { 587 584 IncomingMessage::Dongle(device_msg) => match device_msg.func { 588 585 LovenseDongleMessageFunc::Search => { 589 - if let Some(result) = device_msg.result { 590 - if result == LovenseDongleResultCode::SearchStopped { 586 + if let Some(result) = device_msg.result 587 + && result == LovenseDongleResultCode::SearchStopped { 591 588 self.hub.set_scanning_status(false); 592 589 break; 593 590 } 594 - } 595 591 } 596 592 LovenseDongleMessageFunc::StopSearch => { 597 - if let Some(result) = device_msg.result { 598 - if result == LovenseDongleResultCode::CommandSuccess { 593 + if let Some(result) = device_msg.result 594 + && result == LovenseDongleResultCode::CommandSuccess { 599 595 // Just log and continue here. 600 596 debug!("Lovense dongle stop search command succeeded."); 601 597 } 602 - } 603 598 } 604 599 _ => warn!( 605 600 "LovenseDongleStopScanningAndConnect cannot handle dongle function {:?}", ··· 656 651 IncomingMessage::Dongle(dongle_msg) => { 657 652 match dongle_msg.func { 658 653 LovenseDongleMessageFunc::IncomingStatus => { 659 - if let Some(data) = dongle_msg.data { 660 - if data.status == Some(LovenseDongleResultCode::DeviceDisconnected) { 654 + if let Some(data) = dongle_msg.data 655 + && data.status == Some(LovenseDongleResultCode::DeviceDisconnected) { 661 656 // Device disconnected, emit and return to idle. 662 657 return Some(Box::new(LovenseDongleIdle::new(self.hub))); 663 658 } 664 - } 665 659 } 666 660 _ => { 667 661 if device_read_sender.send(dongle_msg).await.is_err() {
+4 -6
crates/buttplug_server_hwmgr_serial/src/serialport_hardware.rs
··· 184 184 // If we've gotten this far, we can expect we have a serial port definition. 185 185 let mut port_def = None; 186 186 for specifier in specifiers { 187 - if let ProtocolCommunicationSpecifier::Serial(serial) = specifier { 188 - if port_info.port_name == *serial.port() { 187 + if let ProtocolCommunicationSpecifier::Serial(serial) = specifier 188 + && port_info.port_name == *serial.port() { 189 189 port_def = Some(serial.clone()); 190 190 break; 191 191 } 192 - } 193 192 } 194 193 let port_def = port_def.expect("We'll always have a port definition by this point"); 195 194 ··· 248 247 .spawn(move || { 249 248 serial_read_thread(read_port, reader_sender, read_token); 250 249 connected_clone.store(false, Ordering::Relaxed); 251 - if event_stream_clone.receiver_count() != 0 { 252 - if let Err(err) = event_stream_clone.send(HardwareEvent::Disconnected(format!( 250 + if event_stream_clone.receiver_count() != 0 251 + && let Err(err) = event_stream_clone.send(HardwareEvent::Disconnected(format!( 253 252 "{:?}", 254 253 &port_name_clone 255 254 ))) { ··· 258 257 err 259 258 ); 260 259 } 261 - } 262 260 }) 263 261 .expect("Should always be able to create thread"); 264 262
+2 -3
crates/examples/src/bin/device_control.rs
··· 1 - use std::collections::HashMap; 2 1 3 2 use buttplug_client::{ 4 3 ButtplugClient, ··· 50 49 for (_, device) in client.devices() { 51 50 println!("{} supports these outputs:", device.name()); 52 51 for output_type in OutputType::iter() { 53 - for (_, feature) in device.device_features() { 52 + for feature in device.device_features().values() { 54 53 if let Some(output) = feature.feature().output() 55 54 && output.contains(output_type) 56 55 { ··· 68 67 // 69 68 // There's a couple of ways to send this message. 70 69 let devices = client.devices(); 71 - let test_client_device = devices.get(&(device_index as u32)).clone().unwrap(); 70 + let test_client_device = devices.get(&(device_index as u32)).unwrap(); 72 71 73 72 // We can use the convenience functions on ButtplugClientDevice to 74 73 // send the message. This version sets all of the motors on a
-1
crates/examples/src/bin/external_connector.rs
··· 1 1 use buttplug_client::{ 2 2 ButtplugClient, 3 - ButtplugClientEvent, 4 3 connector::ButtplugRemoteClientConnector, 5 4 serializer::ButtplugClientJSONSerializer, 6 5 };
+2 -3
crates/intiface_engine/src/bin/main.rs
··· 258 258 if let Some(value) = args.device_websocket_server_port() { 259 259 builder.device_websocket_server_port(value); 260 260 } 261 - if args.broadcast_server_mdns() { 262 - if let Some(value) = args.mdns_suffix() { 261 + if args.broadcast_server_mdns() 262 + && let Some(value) = args.mdns_suffix() { 263 263 builder.mdns_suffix(value); 264 264 } 265 - } 266 265 Ok(builder.finish()) 267 266 } 268 267 }
+3 -3
crates/intiface_engine/src/buttplug_server.rs
··· 89 89 Ok(server) => Ok(ButtplugRemoteServer::new(server, &Some(sender.clone()))), 90 90 Err(e) => { 91 91 error!("Error starting server: {:?}", e); 92 - return Err(IntifaceEngineError::ButtplugServerError(e)); 92 + Err(IntifaceEngineError::ButtplugServerError(e)) 93 93 } 94 94 } 95 95 } ··· 120 120 let mut server_builder = ButtplugServerBuilder::new( 121 121 dm_builder 122 122 .finish() 123 - .map_err(|e| IntifaceEngineError::ButtplugServerError(e))?, 123 + .map_err(IntifaceEngineError::ButtplugServerError)?, 124 124 ); 125 125 126 126 server_builder ··· 169 169 _, 170 170 ButtplugServerJSONSerializer, 171 171 >::new( 172 - ButtplugWebsocketClientTransport::new_insecure_connector(&addr), 172 + ButtplugWebsocketClientTransport::new_insecure_connector(addr), 173 173 )) 174 174 .await 175 175 } else {
+2 -2
crates/intiface_engine/src/engine.rs
··· 81 81 82 82 let repeater = ButtplugRepeater::new( 83 83 options.repeater_local_port().unwrap(), 84 - &options.repeater_remote_address().as_ref().unwrap(), 84 + options.repeater_remote_address().as_ref().unwrap(), 85 85 self.stop_token.child_token(), 86 86 ); 87 87 select! { ··· 106 106 107 107 // Hang out until those listeners get sick of listening. 108 108 info!("Intiface CLI Setup finished, running server tasks until all joined."); 109 - let mut server = setup_buttplug_server(options, &self.backdoor_server, &dcm).await?; 109 + let mut server = setup_buttplug_server(options, &self.backdoor_server, dcm).await?; 110 110 let dcm = server 111 111 .server() 112 112 .device_manager()
+7 -9
crates/intiface_engine/src/remote_server.rs
··· 86 86 let added_event = ButtplugRemoteServerEvent::DeviceAdded { 87 87 index: da.1.device_index(), 88 88 name: da.1.device_name().clone(), 89 - identifier: device_info.identifier().clone().into(), 89 + identifier: device_info.identifier().clone(), 90 90 display_name: device_info.display_name().clone(), 91 91 }; 92 92 if remote_event_sender.send(added_event).is_err() { ··· 153 153 match server_clone.parse_message(client_message.clone()).await { 154 154 Ok(ret_msg) => { 155 155 // Only send event if we just connected. Sucks to check it on every message but the boolean check should be quick. 156 - if !connected && server_clone.connected() { 157 - if remote_event_sender_clone.receiver_count() > 0 { 158 - if remote_event_sender_clone.send(ButtplugRemoteServerEvent::ClientConnected(server_clone.client_name().unwrap_or("Buttplug Client (No name specified)".to_owned()).clone())).is_err() { 156 + if !connected && server_clone.connected() 157 + && remote_event_sender_clone.receiver_count() > 0 158 + && remote_event_sender_clone.send(ButtplugRemoteServerEvent::ClientConnected(server_clone.client_name().unwrap_or("Buttplug Client (No name specified)".to_owned()).clone())).is_err() { 159 159 error!("Cannot send event to owner, dropping and assuming local server thread has exited."); 160 160 } 161 - } 162 - } 163 161 if connector_clone.send(ret_msg).await.is_err() { 164 162 error!("Cannot send reply to server, dropping and assuming remote server thread has exited."); 165 163 } 166 164 }, 167 165 Err(err_msg) => { 168 - if connector_clone.send(err_msg.into()).await.is_err() { 166 + if connector_clone.send(err_msg).await.is_err() { 169 167 error!("Cannot send reply to server, dropping and assuming remote server thread has exited."); 170 168 } 171 169 } ··· 213 211 } 214 212 Some(msg) => { 215 213 let connector_clone = shared_connector.clone(); 216 - if connector_clone.send(msg.into()).await.is_err() { 214 + if connector_clone.send(msg).await.is_err() { 217 215 error!("Server disappeared, exiting remote server thread."); 218 216 } 219 217 } ··· 263 261 } 264 262 Self { 265 263 event_sender, 266 - server: server, 264 + server, 267 265 disconnect_notifier: Arc::new(Notify::new()), 268 266 } 269 267 }