mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-14 05:33:44 +01:00
Fixed Vec<MessageId> serialization
This commit is contained in:
parent
cf2b01d877
commit
a52fe8eeb5
5 changed files with 40 additions and 0 deletions
crates/teloxide-core/src
|
@ -223,6 +223,11 @@ fn params(params: impl Iterator<Item = impl Borrow<Param>>) -> String {
|
|||
{
|
||||
"\n #[serde(flatten)]"
|
||||
}
|
||||
Type::ArrayOf(b) if **b == Type::RawTy("MessageId".to_string()) =>
|
||||
{
|
||||
"\n #[serde(with = \
|
||||
\"crate::types::vec_msg_id_as_vec_int\")]"
|
||||
}
|
||||
_ => "",
|
||||
};
|
||||
let with = match ty {
|
||||
|
|
|
@ -17,6 +17,7 @@ impl_payload! {
|
|||
/// Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`)
|
||||
pub from_chat_id: Recipient [into],
|
||||
/// Identifiers of 1-100 messages in the chat _from\_chat\_id_ to copy. The identifiers must be specified in a strictly increasing order.
|
||||
#[serde(with = "crate::types::vec_msg_id_as_vec_int")]
|
||||
pub message_ids: Vec<MessageId> [collect],
|
||||
}
|
||||
optional {
|
||||
|
|
|
@ -14,6 +14,7 @@ impl_payload! {
|
|||
/// Identifiers of 1-100 messages to delete. See [`DeleteMessage`] for limitations on which messages can be deleted
|
||||
///
|
||||
/// [`DeleteMessage`]: crate::payloads::DeleteMessage
|
||||
#[serde(with = "crate::types::vec_msg_id_as_vec_int")]
|
||||
pub message_ids: Vec<MessageId> [collect],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ impl_payload! {
|
|||
/// Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`)
|
||||
pub from_chat_id: Recipient [into],
|
||||
/// A JSON-serialized list of 1-100 identifiers of messages in the chat _from\_chat\_id_ to forward. The identifiers must be specified in a strictly increasing order.
|
||||
#[serde(with = "crate::types::vec_msg_id_as_vec_int")]
|
||||
pub message_ids: Vec<MessageId> [collect],
|
||||
}
|
||||
optional {
|
||||
|
|
|
@ -546,3 +546,35 @@ pub(crate) mod option_msg_id_as_int {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod vec_msg_id_as_vec_int {
|
||||
use crate::types::MessageId;
|
||||
|
||||
use serde::{ser::SerializeSeq, Serializer};
|
||||
|
||||
pub(crate) fn serialize<S>(msg_ids: &Vec<MessageId>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut seq = serializer.serialize_seq(Some(msg_ids.len()))?;
|
||||
for e in msg_ids {
|
||||
seq.serialize_element(&e.0)?;
|
||||
}
|
||||
seq.end()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
#[derive(serde::Serialize)]
|
||||
struct Struct {
|
||||
#[serde(with = "crate::types::vec_msg_id_as_vec_int")]
|
||||
msg_ids: Vec<MessageId>,
|
||||
}
|
||||
|
||||
{
|
||||
let s = Struct {msg_ids: vec![MessageId(1), MessageId(2)]};
|
||||
let json = serde_json::to_string(&s).unwrap();
|
||||
assert_eq!(json, "{\"msg_ids\":[1,2]}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue