mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Added default to serialized fields, so they can be deserialized
This commit is contained in:
parent
093377e3ff
commit
6959329c03
4 changed files with 63 additions and 10 deletions
|
@ -29,7 +29,7 @@ pub struct ForceReply {
|
||||||
/// (has reply_to_message_id), sender of the original message.
|
/// (has reply_to_message_id), sender of the original message.
|
||||||
///
|
///
|
||||||
/// [`Message`]: crate::types::Message
|
/// [`Message`]: crate::types::Message
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub selective: bool,
|
pub selective: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,3 +54,20 @@ impl ForceReply {
|
||||||
Self { selective: true, ..self }
|
Self { selective: true, ..self }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize() {
|
||||||
|
let data = r#"
|
||||||
|
{
|
||||||
|
"force_reply": true,
|
||||||
|
"input_field_placeholder": "placeholder",
|
||||||
|
"selective": false
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
serde_json::from_str::<ForceReply>(data).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub struct InputMediaPhoto {
|
||||||
pub caption_entities: Option<Vec<MessageEntity>>,
|
pub caption_entities: Option<Vec<MessageEntity>>,
|
||||||
|
|
||||||
/// Pass `true` if the photo needs to be covered with a spoiler animation.
|
/// Pass `true` if the photo needs to be covered with a spoiler animation.
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub has_spoiler: bool,
|
pub has_spoiler: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ pub struct InputMediaVideo {
|
||||||
pub supports_streaming: Option<bool>,
|
pub supports_streaming: Option<bool>,
|
||||||
|
|
||||||
/// Pass `true` if the video needs to be covered with a spoiler animation.
|
/// Pass `true` if the video needs to be covered with a spoiler animation.
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub has_spoiler: bool,
|
pub has_spoiler: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ pub struct InputMediaAnimation {
|
||||||
|
|
||||||
/// Pass `true` if the animation needs to be covered with a spoiler
|
/// Pass `true` if the animation needs to be covered with a spoiler
|
||||||
/// animation.
|
/// animation.
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub has_spoiler: bool,
|
pub has_spoiler: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,14 +22,14 @@ pub struct KeyboardMarkup {
|
||||||
/// Requests clients to always show the keyboard when the regular keyboard
|
/// Requests clients to always show the keyboard when the regular keyboard
|
||||||
/// is hidden. Defaults to `false`, in which case the custom keyboard
|
/// is hidden. Defaults to `false`, in which case the custom keyboard
|
||||||
/// can be hidden and opened with a keyboard icon.
|
/// can be hidden and opened with a keyboard icon.
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub is_persistent: bool,
|
pub is_persistent: bool,
|
||||||
|
|
||||||
/// Requests clients to resize the keyboard vertically for optimal fit
|
/// Requests clients to resize the keyboard vertically for optimal fit
|
||||||
/// (e.g., make the keyboard smaller if there are just two rows of
|
/// (e.g., make the keyboard smaller if there are just two rows of
|
||||||
/// buttons). Defaults to `false`, in which case the custom keyboard is
|
/// buttons). Defaults to `false`, in which case the custom keyboard is
|
||||||
/// always of the same height as the app's standard keyboard.
|
/// always of the same height as the app's standard keyboard.
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub resize_keyboard: bool,
|
pub resize_keyboard: bool,
|
||||||
|
|
||||||
/// Requests clients to hide the keyboard as soon as it's been used. The
|
/// Requests clients to hide the keyboard as soon as it's been used. The
|
||||||
|
@ -37,12 +37,12 @@ pub struct KeyboardMarkup {
|
||||||
/// display the usual letter-keyboard in the chat – the user can press a
|
/// display the usual letter-keyboard in the chat – the user can press a
|
||||||
/// special button in the input field to see the custom keyboard again.
|
/// special button in the input field to see the custom keyboard again.
|
||||||
/// Defaults to `false`.
|
/// Defaults to `false`.
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub one_time_keyboard: bool,
|
pub one_time_keyboard: bool,
|
||||||
|
|
||||||
/// The placeholder to be shown in the input field when the keyboard is
|
/// The placeholder to be shown in the input field when the keyboard is
|
||||||
/// active; 1-64 characters.
|
/// active; 1-64 characters.
|
||||||
#[serde(skip_serializing_if = "str::is_empty")]
|
#[serde(default, skip_serializing_if = "str::is_empty")]
|
||||||
pub input_field_placeholder: String,
|
pub input_field_placeholder: String,
|
||||||
|
|
||||||
/// Use this parameter if you want to show the keyboard to specific users
|
/// Use this parameter if you want to show the keyboard to specific users
|
||||||
|
@ -55,7 +55,7 @@ pub struct KeyboardMarkup {
|
||||||
/// in the group don’t see the keyboard.
|
/// in the group don’t see the keyboard.
|
||||||
///
|
///
|
||||||
/// [`Message`]: crate::types::Message
|
/// [`Message`]: crate::types::Message
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub selective: bool,
|
pub selective: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,3 +129,23 @@ impl KeyboardMarkup {
|
||||||
Self { selective: true, ..self }
|
Self { selective: true, ..self }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize() {
|
||||||
|
let data = r#"
|
||||||
|
{
|
||||||
|
"keyboard": [[{"text": "a"}, {"text": "b"}], [{"text": "c"}, {"text": "d"}]],
|
||||||
|
"input_field_placeholder": "",
|
||||||
|
"is_persistent": true,
|
||||||
|
"one_time_keyboard": false,
|
||||||
|
"resize_keyboard": true,
|
||||||
|
"selective": false
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
serde_json::from_str::<KeyboardMarkup>(data).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub struct KeyboardRemove {
|
||||||
/// showing the keyboard with poll options to users who haven't voted yet.
|
/// showing the keyboard with poll options to users who haven't voted yet.
|
||||||
///
|
///
|
||||||
/// [`Message`]: crate::types::Message
|
/// [`Message`]: crate::types::Message
|
||||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub selective: bool,
|
pub selective: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,3 +52,19 @@ impl KeyboardRemove {
|
||||||
Self { selective: true, ..self }
|
Self { selective: true, ..self }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize() {
|
||||||
|
let data = r#"
|
||||||
|
{
|
||||||
|
"remove_keyboard": true,
|
||||||
|
"selective": false
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
serde_json::from_str::<KeyboardRemove>(data).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue