Files
empidee/src/commands/querying_mpd_status/stats.rs
h7x4 e910d29aa4
Some checks failed
Build and test / build (push) Successful in 59s
Build and test / check (push) Failing after 1m2s
Build and test / test (push) Successful in 1m42s
Build and test / docs (push) Successful in 1m19s
Rust edition 2024
2025-02-26 16:39:34 +01:00

57 lines
1.7 KiB
Rust

use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::commands::{
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
get_and_parse_optional_property, get_and_parse_property,
};
pub struct Stats;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StatsResponse {
pub uptime: u64,
pub playtime: u64,
pub artists: Option<u64>,
pub albums: Option<u64>,
pub songs: Option<u64>,
pub db_playtime: Option<u64>,
pub db_update: Option<u64>,
}
impl Command for Stats {
type Response = StatsResponse;
const COMMAND: &'static str = "stats";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
debug_assert!(parts.next().is_none());
Ok((Request::Stats, ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: HashMap<_, _> = parts.into();
let uptime = get_and_parse_property!(parts, "uptime", Text);
let playtime = get_and_parse_property!(parts, "playtime", Text);
let artists = get_and_parse_optional_property!(parts, "artists", Text);
let albums = get_and_parse_optional_property!(parts, "albums", Text);
let songs = get_and_parse_optional_property!(parts, "songs", Text);
let db_playtime = get_and_parse_optional_property!(parts, "db_playtime", Text);
let db_update = get_and_parse_optional_property!(parts, "db_update", Text);
Ok(StatsResponse {
uptime,
playtime,
artists,
albums,
songs,
db_playtime,
db_update,
})
}
}