Skip to main content

zai_rs/model/voice_list/
request.rs

1use serde::{Deserialize, Serialize};
2use validator::Validate;
3
4#[derive(Debug, Clone, Serialize, Validate)]
5pub struct VoiceListQuery {
6    /// 音色名称, 如果传入中文, 需要 url encode
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub voice_name: Option<String>,
9    /// 音色类型: OFFICIAL / PRIVATE
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub voice_type: Option<VoiceType>,
12}
13
14impl Default for VoiceListQuery {
15    fn default() -> Self {
16        Self::new()
17    }
18}
19
20impl VoiceListQuery {
21    pub fn new() -> Self {
22        Self {
23            voice_name: None,
24            voice_type: None,
25        }
26    }
27    pub fn with_voice_name(mut self, name: impl Into<String>) -> Self {
28        self.voice_name = Some(name.into());
29        self
30    }
31    pub fn with_voice_type(mut self, vt: VoiceType) -> Self {
32        self.voice_type = Some(vt);
33        self
34    }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(rename_all = "UPPERCASE")]
39pub enum VoiceType {
40    Official,
41    Private,
42}
43
44impl VoiceType {
45    pub fn as_str(&self) -> &'static str {
46        match self {
47            VoiceType::Official => "OFFICIAL",
48            VoiceType::Private => "PRIVATE",
49        }
50    }
51}