mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Add StoryId
struct
This commit is contained in:
parent
7e4d29cf15
commit
7d4fd7e295
2 changed files with 31 additions and 0 deletions
|
@ -126,6 +126,7 @@ pub use shipping_query::*;
|
||||||
pub use sticker::*;
|
pub use sticker::*;
|
||||||
pub use sticker_set::*;
|
pub use sticker_set::*;
|
||||||
pub use story::*;
|
pub use story::*;
|
||||||
|
pub use story_id::*;
|
||||||
pub use successful_payment::*;
|
pub use successful_payment::*;
|
||||||
pub use switch_inline_query_chosen_chat::*;
|
pub use switch_inline_query_chosen_chat::*;
|
||||||
pub use target_message::*;
|
pub use target_message::*;
|
||||||
|
@ -297,6 +298,7 @@ mod inline_query_result_photo;
|
||||||
mod inline_query_result_venue;
|
mod inline_query_result_venue;
|
||||||
mod inline_query_result_video;
|
mod inline_query_result_video;
|
||||||
mod inline_query_result_voice;
|
mod inline_query_result_voice;
|
||||||
|
mod story_id;
|
||||||
|
|
||||||
mod encrypted_credentials;
|
mod encrypted_credentials;
|
||||||
mod encrypted_passport_element;
|
mod encrypted_passport_element;
|
||||||
|
|
29
crates/teloxide-core/src/types/story_id.rs
Normal file
29
crates/teloxide-core/src/types/story_id.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Identifier of a story.
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
#[derive(Debug, derive_more::Display)]
|
||||||
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(transparent)]
|
||||||
|
pub struct StoryId(pub u64);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// Test that `StoryId` is serialized as the underlying integer
|
||||||
|
#[test]
|
||||||
|
fn deser() {
|
||||||
|
let story_id = S { id: StoryId(17) };
|
||||||
|
let json = r#"{"id":17}"#;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||||
|
struct S {
|
||||||
|
id: StoryId,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(serde_json::to_string(&story_id).unwrap(), json);
|
||||||
|
assert_eq!(story_id, serde_json::from_str(json).unwrap());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue