Add StoryId struct

This commit is contained in:
Andrey Brusnik 2024-07-20 20:24:39 +04:00
parent 7e4d29cf15
commit 7d4fd7e295
No known key found for this signature in database
GPG key ID: D33232F28CFF442C
2 changed files with 31 additions and 0 deletions

View file

@ -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;

View 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());
}
}