common/types: add better alias for AudioOutputId

This commit is contained in:
2025-11-25 04:22:30 +09:00
parent e5f70ca87a
commit 9ca6544057
6 changed files with 21 additions and 8 deletions

View File

@@ -20,10 +20,13 @@ impl Command for DisableOutput {
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let output_id = output_id
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, output_id.to_owned()))?;
debug_assert!(parts.next().is_none());
Ok((Request::DisableOutput(output_id.to_string()), ""))
Ok((Request::DisableOutput(output_id), ""))
}
fn parse_response(

View File

@@ -20,10 +20,13 @@ impl Command for EnableOutput {
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let output_id = output_id
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, output_id.to_owned()))?;
debug_assert!(parts.next().is_none());
Ok((Request::EnableOutput(output_id.to_string()), ""))
Ok((Request::EnableOutput(output_id), ""))
}
fn parse_response(

View File

@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, Request, RequestParserResult, ResponseParserError},
common::AudioOutputId,
request_tokenizer::RequestTokenizer,
response_tokenizer::{ResponseAttributes, expect_property_type},
};
@@ -12,7 +13,7 @@ pub struct Outputs;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Output {
pub id: u64,
pub id: AudioOutputId,
pub name: String,
pub plugin: String,
pub enabled: bool,
@@ -40,7 +41,7 @@ impl Command for Outputs {
) -> Result<Self::Response, ResponseParserError<'_>> {
let mut outputs = Vec::new();
let mut id: Option<u64> = None;
let mut id: Option<AudioOutputId> = None;
let mut name: Option<String> = None;
let mut plugin: Option<String> = None;
let mut enabled: Option<bool> = None;
@@ -64,7 +65,7 @@ impl Command for Outputs {
attributes = HashMap::new();
let id_s = expect_property_type!(Some(v), k, Text);
id = Some(
id_s.parse::<u64>()
id_s.parse()
.map_err(|_| ResponseParserError::SyntaxError(0, id_s))?,
);
}

View File

@@ -33,6 +33,9 @@ impl Command for OutputSet {
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let output_id = output_id
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, output_id.to_owned()))?;
let attribute_name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let attribute_value = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
@@ -40,7 +43,7 @@ impl Command for OutputSet {
Ok((
Request::OutputSet(
output_id.to_string(),
output_id,
attribute_name.to_string(),
attribute_value.to_string(),
),

View File

@@ -20,10 +20,13 @@ impl Command for ToggleOutput {
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let output_id = output_id
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, output_id.to_owned()))?;
debug_assert!(parts.next().is_none());
Ok((Request::ToggleOutput(output_id.to_string()), ""))
Ok((Request::ToggleOutput(output_id), ""))
}
fn parse_response(

View File

@@ -30,6 +30,7 @@ pub use time_interval::TimeInterval;
pub use volume_value::VolumeValue;
pub use window_range::WindowRange;
pub type AudioOutputId = u32;
pub type Offset = u32;
pub type PlaylistName = String;
pub type PlaylistVersion = u32;
@@ -40,7 +41,6 @@ pub type SongPosition = u32;
pub type TimeWithFractions = f64;
// TODO: use a proper types
pub type AudioOutputId = String;
pub type Feature = String;
pub type PartitionName = String;
pub type Path = String;