Skip to content

Commit

Permalink
chore: run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
qdot committed May 13, 2024
1 parent 96bb3de commit d4be80a
Show file tree
Hide file tree
Showing 18 changed files with 334 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ use getset::{Getters, MutGetters, Setters};
use serde::{ser::SerializeSeq, Deserialize, Serialize, Serializer};
use std::ops::RangeInclusive;

use super::{ButtplugActuatorFeatureMessageType, ButtplugSensorFeatureMessageType, DeviceFeature, FeatureType};
use super::{
ButtplugActuatorFeatureMessageType,
ButtplugSensorFeatureMessageType,
DeviceFeature,
FeatureType,
};

#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ActuatorType {
Expand Down
47 changes: 28 additions & 19 deletions buttplug/src/core/message/device_feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
// for full license information.

use crate::core::{errors::ButtplugDeviceError, message::{ButtplugDeviceMessageType, Endpoint}};
use crate::core::{
errors::ButtplugDeviceError,
message::{ButtplugDeviceMessageType, Endpoint},
};
use getset::{Getters, MutGetters, Setters};
use serde::{Deserialize, Serialize, Serializer, ser::SerializeSeq};
use serde::{ser::SerializeSeq, Deserialize, Serialize, Serializer};
use std::{collections::HashSet, ops::RangeInclusive};

use super::{ActuatorType, ButtplugActuatorFeatureMessageType, ButtplugSensorFeatureMessageType, SensorType};
use super::{
ActuatorType,
ButtplugActuatorFeatureMessageType,
ButtplugSensorFeatureMessageType,
SensorType,
};

#[derive(Debug, Default, Display, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum FeatureType {
Expand Down Expand Up @@ -130,10 +138,7 @@ impl DeviceFeature {
}
}

fn range_serialize<S>(
range: &RangeInclusive<u32>,
serializer: S,
) -> Result<S::Ok, S::Error>
fn range_serialize<S>(range: &RangeInclusive<u32>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
Expand Down Expand Up @@ -161,7 +166,7 @@ where
pub struct DeviceFeatureActuatorSerialized {
#[getset(get = "pub")]
#[serde(rename = "step-range")]
#[serde(serialize_with="range_serialize")]
#[serde(serialize_with = "range_serialize")]
step_range: RangeInclusive<u32>,
// This doesn't exist in base configs, so when we load these from the base config file, we'll just
// copy the step_range value.
Expand All @@ -175,17 +180,17 @@ pub struct DeviceFeatureActuatorSerialized {
}

#[derive(Clone, Debug, PartialEq, Eq, Getters, MutGetters, Setters, Serialize, Deserialize)]
#[serde(from="DeviceFeatureActuatorSerialized")]
#[serde(from = "DeviceFeatureActuatorSerialized")]
pub struct DeviceFeatureActuator {
#[getset(get = "pub")]
#[serde(rename = "step-range")]
#[serde(serialize_with="range_serialize")]
#[serde(serialize_with = "range_serialize")]
step_range: RangeInclusive<u32>,
// This doesn't exist in base configs, so when we load these from the base config file, we'll just
// copy the step_range value.
#[getset(get = "pub")]
#[serde(rename = "step-limit")]
#[serde(serialize_with="range_serialize")]
#[serde(serialize_with = "range_serialize")]
step_limit: RangeInclusive<u32>,
#[getset(get = "pub")]
#[serde(rename = "messages")]
Expand All @@ -194,11 +199,11 @@ pub struct DeviceFeatureActuator {

impl From<DeviceFeatureActuatorSerialized> for DeviceFeatureActuator {
fn from(value: DeviceFeatureActuatorSerialized) -> Self {
Self {
step_range: value.step_range.clone(),
step_limit: value.step_limit.unwrap_or(value.step_range),
messages: value.messages
}
Self {
step_range: value.step_range.clone(),
step_limit: value.step_limit.unwrap_or(value.step_range),
messages: value.messages,
}
}
}

Expand All @@ -217,9 +222,13 @@ impl DeviceFeatureActuator {

pub fn is_valid(&self) -> Result<(), ButtplugDeviceError> {
if self.step_range.is_empty() || self.step_range.start() > self.step_range.end() {
Err(ButtplugDeviceError::DeviceConfigurationError(format!("Step range out of order, must be start <= x <= end.")))
Err(ButtplugDeviceError::DeviceConfigurationError(format!(
"Step range out of order, must be start <= x <= end."
)))
} else if self.step_limit.is_empty() || self.step_limit.start() > self.step_limit.end() {
Err(ButtplugDeviceError::DeviceConfigurationError(format!("Step limit out of order, must be start <= x <= end.")))
Err(ButtplugDeviceError::DeviceConfigurationError(format!(
"Step limit out of order, must be start <= x <= end."
)))
} else {
Ok(())
}
Expand All @@ -232,7 +241,7 @@ impl DeviceFeatureActuator {
pub struct DeviceFeatureSensor {
#[getset(get = "pub", get_mut = "pub(super)")]
#[serde(rename = "value-range")]
#[serde(serialize_with="range_sequence_serialize")]
#[serde(serialize_with = "range_sequence_serialize")]
value_range: Vec<RangeInclusive<i32>>,
#[getset(get = "pub")]
#[serde(rename = "messages")]
Expand Down
6 changes: 4 additions & 2 deletions buttplug/src/core/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl Ord for ButtplugDeviceMessageType {
pub enum ButtplugActuatorFeatureMessageType {
ScalarCmd,
RotateCmd,
LinearCmd
LinearCmd,
}

impl From<ButtplugActuatorFeatureMessageType> for ButtplugDeviceMessageType {
Expand All @@ -291,7 +291,9 @@ impl From<ButtplugSensorFeatureMessageType> for ButtplugDeviceMessageType {
fn from(value: ButtplugSensorFeatureMessageType) -> Self {
match value {
ButtplugSensorFeatureMessageType::SensorReadCmd => ButtplugDeviceMessageType::SensorReadCmd,
ButtplugSensorFeatureMessageType::SensorSubscribeCmd => ButtplugDeviceMessageType::SensorSubscribeCmd,
ButtplugSensorFeatureMessageType::SensorSubscribeCmd => {
ButtplugDeviceMessageType::SensorSubscribeCmd
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl UserDeviceCustomization {
display_name: display_name.clone(),
allow,
deny,
index
index,
}
}
}
Expand All @@ -58,7 +58,7 @@ pub struct UserDeviceDefinition {
/// Message attributes for this device instance.
features: Vec<DeviceFeature>,
/// Per-user configurations specific to this device instance.
#[serde(rename="user-config")]
#[serde(rename = "user-config")]
user_config: UserDeviceCustomization,
}

Expand All @@ -82,8 +82,8 @@ impl UserDeviceDefinition {
features: def.features().clone(),
user_config: UserDeviceCustomization {
index: index,
.. Default::default()
}
..Default::default()
},
}
}

Expand Down
3 changes: 1 addition & 2 deletions buttplug/src/server/device/configuration/identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ impl From<&UserDeviceIdentifier> for BaseDeviceIdentifier {

impl PartialEq<UserDeviceIdentifier> for BaseDeviceIdentifier {
fn eq(&self, other: &UserDeviceIdentifier) -> bool {
self.protocol == *other.protocol()
&& self.identifier == *other.identifier()
self.protocol == *other.protocol() && self.identifier == *other.identifier()
}
}

0 comments on commit d4be80a

Please sign in to comment.