Buttplug sex toy control library

chore: Clippy fixes

+28 -44
+3 -3
crates/buttplug_client/src/device/command.rs
··· 69 69 } 70 70 } 71 71 72 - impl Into<OutputType> for &ClientDeviceOutputCommand { 73 - fn into(self) -> OutputType { 74 - match self { 72 + impl From<&ClientDeviceOutputCommand> for OutputType { 73 + fn from(val: &ClientDeviceOutputCommand) -> Self { 74 + match val { 75 75 ClientDeviceOutputCommand::Vibrate(_) | ClientDeviceOutputCommand::VibrateFloat(_) => { 76 76 OutputType::Vibrate 77 77 }
+1 -1
crates/buttplug_client/src/device/feature.rs
··· 160 160 OutputCommand::Oscillate(OutputValue::new(self.check_step_value(output, *v as i32)?)) 161 161 } 162 162 ClientDeviceOutputCommand::Rotate(v) => { 163 - OutputCommand::Rotate(OutputValue::new(self.check_step_value(output, *v as i32)?)) 163 + OutputCommand::Rotate(OutputValue::new(self.check_step_value(output, (*v))?)) 164 164 } 165 165 ClientDeviceOutputCommand::Constrict(v) => { 166 166 OutputCommand::Constrict(OutputValue::new(self.check_step_value(output, *v as i32)?))
+1 -1
crates/buttplug_server/src/device/protocol_impl/fredorch.rs
··· 290 290 duration: u32, 291 291 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 292 292 let previous_position = self.previous_position.load(Ordering::Relaxed); 293 - let distance = (previous_position as i32 - position as i32).abs() as u32; 293 + let distance = (previous_position as i32 - position as i32).unsigned_abs(); 294 294 // The Fredorch only has 15 positions, but scales them to 0-150 295 295 let pos = (position * 10) as u8; 296 296
+1 -8
crates/buttplug_server/src/device/protocol_impl/galaku.rs
··· 131 131 } 132 132 } 133 133 134 + #[derive(Default)] 134 135 pub struct Galaku { 135 136 is_caiping_pump_device: bool, 136 137 speeds: Vec<AtomicU8>, 137 138 } 138 139 139 - impl Default for Galaku { 140 - fn default() -> Self { 141 - Self { 142 - is_caiping_pump_device: false, 143 - speeds: vec![], 144 - } 145 - } 146 - } 147 140 impl Galaku { 148 141 fn handle_local_output_cmd( 149 142 &self,
+1 -1
crates/buttplug_server/src/device/protocol_impl/hismith_mini.rs
··· 198 198 ) 199 199 .into(), 200 200 HardwareWriteCmd::new( 201 - &vec![HISMITH_MINI_ROTATE_DIRECTIOM_UUID], 201 + &[HISMITH_MINI_ROTATE_DIRECTIOM_UUID], 202 202 Endpoint::Tx, 203 203 vec![ 204 204 0xCC,
+1 -1
crates/buttplug_server/src/device/protocol_impl/lovense/lovense_rotate_vibrator.rs
··· 39 39 _feature_id: Uuid, 40 40 speed: i32, 41 41 ) -> Result<Vec<HardwareCommand>, ButtplugDeviceError> { 42 - form_rotate_with_direction_command(speed.abs() as u32, speed < 0) 42 + form_rotate_with_direction_command(speed.unsigned_abs(), speed < 0) 43 43 } 44 44 45 45 fn handle_battery_level_cmd(
+1 -1
crates/buttplug_server/src/message/v4/checked_output_cmd.rs
··· 108 108 let output_type = cmd.command().as_output_type(); 109 109 let value = cmd.command().value(); 110 110 let new_value = output_map 111 - .calculate_from_value(output_type, value as i32) 111 + .calculate_from_value(output_type, value) 112 112 .map_err(|e| { 113 113 error!("{:?}", e); 114 114 ButtplugDeviceError::DeviceStepRangeError(0, value)
+1 -1
crates/buttplug_server/src/message/v4/checked_output_vec_cmd.rs
··· 387 387 ButtplugError::from(ButtplugMessageError::InvalidMessageContents( 388 388 "Position should be 0.0 < x < 1.0".to_owned(), 389 389 )) 390 - })? as i32 390 + })? 391 391 * (if cmd.clockwise() { 1 } else { -1 }), 392 392 )), 393 393 ));
+1 -1
crates/buttplug_server_device_config/src/device_config_file/feature.rs
··· 502 502 id: value.id(), 503 503 base_id: value 504 504 .base_id() 505 - .expect(&format!("Should have base id: {:?}", value)), 505 + .unwrap_or_else(|| panic!("Should have base id: {:?}", value)), 506 506 output: value.output().as_ref().map(|x| x.into()), 507 507 } 508 508 }
+1 -3
crates/buttplug_server_device_config/src/device_config_file/mod.rs
··· 196 196 if let Ok(loaded_user_config) = user_device_config_pair 197 197 .config() 198 198 .build_from_base_definition(base_config.1) 199 - { 200 - if let Err(e) = dcm_builder 199 + && let Err(e) = dcm_builder 201 200 .user_device_definition(user_device_config_pair.identifier(), &loaded_user_config) 202 201 { 203 202 error!( ··· 205 204 e, user_config 206 205 ) 207 206 } 208 - } 209 207 } else { 210 208 error!( 211 209 "Device identifier {:?} does not have a match base identifier that matches anything in the base config, removing from database.",
+3 -4
crates/intiface_engine/src/bin/main.rs
··· 217 217 "Intiface CLI Options: User Device Config {}", 218 218 userdeviceconfig 219 219 ); 220 - builder.user_device_config_path(&userdeviceconfig); 220 + builder.user_device_config_path(userdeviceconfig); 221 221 match fs::read_to_string(userdeviceconfig) { 222 222 Ok(cfg) => { 223 223 builder.user_device_config_json(&cfg); ··· 267 267 if let Some(value) = args.rest_api_port() { 268 268 builder.rest_api_port(*value); 269 269 } 270 - if args.broadcast_server_mdns() { 271 - if let Some(value) = args.mdns_suffix() { 270 + if args.broadcast_server_mdns() 271 + && let Some(value) = args.mdns_suffix() { 272 272 builder.mdns_suffix(value); 273 273 } 274 - } 275 274 Ok(builder.finish()) 276 275 } 277 276 }
+13 -19
crates/intiface_engine/src/rest_server.rs
··· 1 1 use std::{ 2 - collections::BTreeMap, convert::Infallible, io, net::SocketAddr, str::FromStr, sync::Arc, 2 + collections::BTreeMap, convert::Infallible, io, net::SocketAddr, sync::Arc, 3 3 }; 4 4 5 5 use axum::{ ··· 13 13 routing::{get, put}, 14 14 }; 15 15 use buttplug_client::{ 16 - ButtplugClient, ButtplugClientDevice, ButtplugClientError, ButtplugClientEvent, 16 + ButtplugClient, ButtplugClientDevice, ButtplugClientError, 17 17 device::{ClientDeviceFeature, ClientDeviceOutputCommand}, 18 18 }; 19 19 use buttplug_client_in_process::ButtplugInProcessClientConnectorBuilder; ··· 127 127 client 128 128 .start_scanning() 129 129 .await 130 - .map_err(|e| IntifaceRestError::ButtplugClientError(e)) 130 + .map_err(IntifaceRestError::ButtplugClientError) 131 131 } 132 132 133 133 async fn stop_scanning(State(client): State<Arc<ButtplugClient>>) -> Result<(), IntifaceRestError> { 134 134 client 135 135 .stop_scanning() 136 136 .await 137 - .map_err(|e| IntifaceRestError::ButtplugClientError(e)) 137 + .map_err(IntifaceRestError::ButtplugClientError) 138 138 } 139 139 140 140 async fn stop_all_devices( ··· 143 143 client 144 144 .stop_all_devices() 145 145 .await 146 - .map_err(|e| IntifaceRestError::ButtplugClientError(e)) 146 + .map_err(IntifaceRestError::ButtplugClientError) 147 147 } 148 148 149 149 async fn stop_device( 150 150 State(client): State<Arc<ButtplugClient>>, 151 151 Path(index): Path<u32>, 152 152 ) -> Result<(), IntifaceRestError> { 153 - Ok( 154 - get_device(&client, index)? 153 + get_device(&client, index)? 155 154 .stop() 156 155 .await 157 - .map_err(|e| IntifaceRestError::ButtplugClientError(e))?, 158 - ) 156 + .map_err(IntifaceRestError::ButtplugClientError) 159 157 } 160 158 161 159 async fn set_device_output( ··· 163 161 Path((index, command, level)): Path<(u32, OutputType, f64)>, 164 162 ) -> Result<(), IntifaceRestError> { 165 163 let cmd = ClientDeviceOutputCommand::from_command_value_float(command, level) 166 - .map_err(|e| IntifaceRestError::ButtplugClientError(e))?; 164 + .map_err(IntifaceRestError::ButtplugClientError)?; 167 165 168 - Ok( 169 - get_device(&client, index)? 166 + get_device(&client, index)? 170 167 .send_command(&cmd) 171 168 .await 172 - .map_err(|e| IntifaceRestError::ButtplugClientError(e))?, 173 - ) 169 + .map_err(IntifaceRestError::ButtplugClientError) 174 170 } 175 171 176 172 async fn set_feature_output( ··· 178 174 Path((index, feature_index, command, level)): Path<(u32, u32, OutputType, f64)>, 179 175 ) -> Result<(), IntifaceRestError> { 180 176 let cmd = ClientDeviceOutputCommand::from_command_value_float(command, level) 181 - .map_err(|e| IntifaceRestError::ButtplugClientError(e))?; 177 + .map_err(IntifaceRestError::ButtplugClientError)?; 182 178 183 - Ok( 184 - get_feature(&client, index, feature_index)? 179 + get_feature(&client, index, feature_index)? 185 180 .send_command(&cmd) 186 181 .await 187 - .map_err(|e| IntifaceRestError::ButtplugClientError(e))?, 188 - ) 182 + .map_err(IntifaceRestError::ButtplugClientError) 189 183 } 190 184 191 185 async fn get_devices(