mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Make ResponseParameters
more rust-friendly
This commit is contained in:
parent
7e14e8f9e7
commit
4d241131fc
2 changed files with 30 additions and 3 deletions
|
@ -13,3 +13,5 @@ serde = {version = "1.0.92", features = ["derive"] }
|
|||
lazy_static = "1.3"
|
||||
apply = "0.2.2"
|
||||
derive_more = "0.15.0"
|
||||
|
||||
tokio = "0.1"
|
|
@ -1,5 +1,30 @@
|
|||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
|
||||
pub struct ResponseParameters {
|
||||
pub migrate_to_chat_id: Option<i64>,
|
||||
pub retry_after: Option<i64>,
|
||||
#[serde(tag = "type")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ResponseParameters {
|
||||
MigrateToChatId(i64),
|
||||
RetryAfter(i64),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn migrate_to_chat_id_deserialization() {
|
||||
let expected_struct = ResponseParameters::MigrateToChatId(123456);
|
||||
let actual_json: ResponseParameters = serde_json::from_str(
|
||||
r#"{"migrate_to_chat_id":123456}"#
|
||||
).unwrap();
|
||||
|
||||
assert_eq!(expected_json, actual_json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retry_after_deserialization() {
|
||||
let expected_struct = ResponseParameters::RetryAfter(123456);
|
||||
let actual_json: ResponseParameters = serde_json::from_str(
|
||||
r#"{"retry_after":123456}"#
|
||||
).unwrap();
|
||||
|
||||
assert_eq!(expected_json, actual_json);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue