Applied rust fmt
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-10 01:33:39 +02:00
parent de9203b8d5
commit 3645b53f7c
29 changed files with 842 additions and 375 deletions

View File

@@ -1,6 +1,6 @@
use serde::Serialize;
use crate::{response::State, errors::ErrorCode};
use crate::{errors::ErrorCode, response::State};
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
@@ -14,7 +14,11 @@ pub struct Payload {
impl Payload {
pub fn new() -> Self {
Self { error_code: None, debug_string: None, commands: Vec::new() }
Self {
error_code: None,
debug_string: None,
commands: Vec::new(),
}
}
pub fn add_command(&mut self, command: Command) {
@@ -44,7 +48,12 @@ pub struct Command {
impl Command {
pub fn new(status: Status) -> Self {
Self { error_code: None, ids: Vec::new(), status, states: None }
Self {
error_code: None,
ids: Vec::new(),
status,
states: None,
}
}
pub fn add_id(&mut self, id: &str) {
@@ -78,7 +87,10 @@ pub enum Status {
#[cfg(test)]
mod tests {
use super::*;
use crate::{response::{Response, ResponsePayload, State}, errors::DeviceError};
use crate::{
errors::DeviceError,
response::{Response, ResponsePayload, State},
};
#[test]
fn serialize() {
@@ -98,7 +110,10 @@ mod tests {
command.ids.push("456".into());
execute_resp.add_command(command);
let resp = Response::new("ff36a3cc-ec34-11e6-b1a0-64510650abcf", ResponsePayload::Execute(execute_resp));
let resp = Response::new(
"ff36a3cc-ec34-11e6-b1a0-64510650abcf",
ResponsePayload::Execute(execute_resp),
);
let json = serde_json::to_string(&resp).unwrap();

View File

@@ -2,7 +2,7 @@ use std::collections::HashMap;
use serde::Serialize;
use crate::{response::State, errors::ErrorCode};
use crate::{errors::ErrorCode, response::State};
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
@@ -16,7 +16,11 @@ pub struct Payload {
impl Payload {
pub fn new() -> Self {
Self { error_code: None, debug_string: None, devices: HashMap::new() }
Self {
error_code: None,
debug_string: None,
devices: HashMap::new(),
}
}
pub fn add_device(&mut self, id: &str, device: Device) {
@@ -53,7 +57,12 @@ pub struct Device {
impl Device {
pub fn new() -> Self {
Self { online: true, status: Status::Success, error_code: None, state: State::default() }
Self {
online: true,
status: Status::Success,
error_code: None,
state: State::default(),
}
}
pub fn set_offline(&mut self) {
@@ -93,7 +102,10 @@ mod tests {
device.state.on = Some(false);
query_resp.add_device("456", device);
let resp = Response::new("ff36a3cc-ec34-11e6-b1a0-64510650abcf", ResponsePayload::Query(query_resp));
let resp = Response::new(
"ff36a3cc-ec34-11e6-b1a0-64510650abcf",
ResponsePayload::Query(query_resp),
);
let json = serde_json::to_string(&resp).unwrap();

View File

@@ -3,8 +3,8 @@ use serde::Serialize;
use crate::attributes::Attributes;
use crate::device;
use crate::errors::ErrorCode;
use crate::types::Type;
use crate::traits::Trait;
use crate::types::Type;
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
@@ -19,7 +19,12 @@ pub struct Payload {
impl Payload {
pub fn new(agent_user_id: &str) -> Self {
Self { agent_user_id: agent_user_id.into(), error_code: None, debug_string: None, devices: Vec::new() }
Self {
agent_user_id: agent_user_id.into(),
error_code: None,
debug_string: None,
devices: Vec::new(),
}
}
pub fn add_device(&mut self, device: Device) {
@@ -64,7 +69,11 @@ impl Device {
#[cfg(test)]
mod tests {
use super::*;
use crate::{response::{Response, ResponsePayload}, types::Type, traits::Trait};
use crate::{
response::{Response, ResponsePayload},
traits::Trait,
types::Type,
};
#[test]
fn serialize() {
@@ -85,7 +94,10 @@ mod tests {
sync_resp.add_device(device);
let resp = Response::new("ff36a3cc-ec34-11e6-b1a0-64510650abcf", ResponsePayload::Sync(sync_resp));
let resp = Response::new(
"ff36a3cc-ec34-11e6-b1a0-64510650abcf",
ResponsePayload::Sync(sync_resp),
);
let json = serde_json::to_string(&resp).unwrap();