Add serialize derive to all structs

This commit is contained in:
kageru 2020-07-24 18:30:59 +02:00
parent f3738b1af7
commit c1499ff9b3
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -1,11 +1,11 @@
use chrono::prelude::*; use chrono::prelude::*;
use helpers::*; use helpers::*;
use serde::Deserialize; use serde::{Deserialize, Serialize};
use std::{fmt, time::Duration}; use std::{fmt, time::Duration};
/// All information about a track. This is returned by the `currentsong`, `queue`, or /// All information about a track. This is returned by the `currentsong`, `queue`, or
/// `playlistinfo` commands. /// `playlistinfo` commands.
#[derive(Deserialize, Clone, Debug, Default, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(default)] #[serde(default)]
pub struct Track { pub struct Track {
pub file: String, pub file: String,
@ -50,7 +50,7 @@ pub struct Track {
/// An empty struct that can be used as the response data for commands that only ever return `OK` /// An empty struct that can be used as the response data for commands that only ever return `OK`
/// or an error message, e.g. `consume` or other boolean toggles. /// or an error message, e.g. `consume` or other boolean toggles.
#[derive(Deserialize, PartialEq, Debug)] #[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct UnitResponse {} pub struct UnitResponse {}
/// The position of an item in a list with an optional total length. /// The position of an item in a list with an optional total length.
@ -58,7 +58,7 @@ pub struct UnitResponse {}
/// Can be used for e.g. track number, /// Can be used for e.g. track number,
/// where `Position { 3, 12 }` represents track 3 of a CD with 12 tracks, /// where `Position { 3, 12 }` represents track 3 of a CD with 12 tracks,
/// or disc numbers in a multi-disc set. /// or disc numbers in a multi-disc set.
#[derive(Deserialize, Clone, Debug, Default, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
pub struct Position { pub struct Position {
pub item_position: u16, pub item_position: u16,
pub total_items: Option<u16>, pub total_items: Option<u16>,
@ -80,7 +80,7 @@ impl fmt::Display for Position {
/// i.e. on a server with no pulse or alsa output configured. /// i.e. on a server with no pulse or alsa output configured.
/// Output via httpd might be used instead /// Output via httpd might be used instead
/// but will result in empty `volume` and `audio` fields. /// but will result in empty `volume` and `audio` fields.
#[derive(Deserialize, Clone, Debug, Default, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(default)] #[serde(default)]
pub struct Status { pub struct Status {
pub volume: Option<u8>, pub volume: Option<u8>,
@ -128,7 +128,7 @@ pub struct Status {
/// Properly parsing `listfiles` into a Vector of some enum with variants for file and directory /// Properly parsing `listfiles` into a Vector of some enum with variants for file and directory
/// would make the deserialization code a lot more complicated, so I’m not interested in doing that /// would make the deserialization code a lot more complicated, so I’m not interested in doing that
/// at this point in time. /// at this point in time.
#[derive(Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct File { pub struct File {
#[serde(alias = "directory", rename = "file")] #[serde(alias = "directory", rename = "file")]
pub name: String, pub name: String,
@ -150,7 +150,7 @@ impl File {
} }
} }
#[derive(Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub enum State { pub enum State {
Stop, Stop,
Play, Play,
@ -165,7 +165,7 @@ impl Default for State {
} }
/// Database statistics as returned by the `stats` command. /// Database statistics as returned by the `stats` command.
#[derive(Deserialize, Clone, Debug, Default, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(default)] #[serde(default)]
pub struct Stats { pub struct Stats {
pub artists: u32, pub artists: u32,