fy_cli_rust/
model.rs

1use serde::{Deserialize, Serialize};
2use std::default::Default;
3
4// 交互的响应
5pub enum UserRes {
6    QUERY,
7    SETKEY
8}
9
10#[derive(Serialize, Debug)]
11pub struct Params {
12    pub q: String,
13    pub salt: String,
14    pub from: String,
15    pub to: String,
16    #[serde(rename = "appKey")]
17    pub app_key: String,
18    pub sign: String,
19    #[serde(rename = "signType")]
20    pub sign_type: String,
21    pub curtime: String,
22    pub ext: Option<String>,
23    pub voice: Option<String>,
24    pub strict: Option<bool>,
25    pub vocabld: Option<String>,
26}
27
28impl Default for Params {
29    fn default() -> Self {
30        Params {
31            q: String::new(),
32            salt: String::new(),
33            from: "auto".to_string(),
34            to: "auto".to_string(),
35            app_key: String::new(),
36            sign: String::new(),
37            sign_type: "v3".to_string(),
38            curtime: String::new(),
39            ext: None,
40            voice: None,
41            strict: None,
42            vocabld: None,
43        }
44    }
45}
46
47#[derive(Deserialize, Debug)]
48pub struct BasicObj {
49    pub explains: Vec<String>,
50}
51
52#[derive(Deserialize, Debug)]
53pub struct WebItem {
54    pub key: String,
55    pub value: Vec<String>,
56}
57
58#[derive(Deserialize, Debug)]
59struct DictObj {
60    url: String,
61}
62
63#[derive(Deserialize, Debug)]
64struct WebDictObj {
65    url: String,
66}
67
68#[derive(Deserialize, Debug)]
69pub struct TransformRes {
70    #[serde(rename = "errorCode")]
71    pub error_code: String,
72    pub query: Option<String>,
73    translation: Option<Vec<String>>,
74    pub basic: Option<BasicObj>,
75    pub web: Option<Vec<WebItem>>,
76    l: String,
77    dict: Option<DictObj>,
78    webdict: Option<WebDictObj>,
79    #[serde(rename = "tSpeakUrl")]
80    t_speak_url: Option<String>,
81    #[serde(rename = "speakUrl")]
82    speak_url: Option<String>,
83    #[serde(rename = "returnPhrase")]
84    return_phrase: Option<Vec<String>>,
85}
86
87#[derive(Serialize, Deserialize, Debug)]
88pub struct UserKey {
89    pub app_key: String,
90    pub app_secure: String,
91}
92
93impl Default for UserKey {
94    fn default() -> Self {
95        UserKey {
96            app_key: String::new(),
97            app_secure: String::new(),
98        }
99    }
100}