Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix serialization of InlineQueryResult #230

Merged
merged 10 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async-telegram-trait = ["dep:async-trait"]

[lints.rust]
unsafe_code = "forbid"
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust_analyzer)'] }
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Veetaha might interest this. There is also elastio/bon#212 which might be similar / related. 👀

Copy link
Contributor

@Veetaha Veetaha Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a regression on nightly only. It was worked around in a 3.0.2 version. I think you can upgrade to this version without a migration

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be its own PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there is a dependabot PR #229

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be its own PR?

To extend to that, this only fails on nightly so I would just ignore this for this PR and remove this change. A bon patch is there, and I could also see rust_analyzer being added to the list of well known values. So a change in this repo seems in the wrong place either way.

[lints.clippy]
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
Expand Down
73 changes: 54 additions & 19 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,79 @@ impl From<String> for FileUpload {
#[serde(tag = "type")]
ayrat555 marked this conversation as resolved.
Show resolved Hide resolved
pub enum InlineQueryResult {
#[serde(rename = "audio")]
CachedAudio(InlineQueryResultCachedAudio),
AudioOrCachedAudio(InlineQueryResultAudioOrCachedAudio),
EdJoPaTo marked this conversation as resolved.
Show resolved Hide resolved
#[serde(rename = "document")]
CachedDocument(InlineQueryResultCachedDocument),
DocumentOrCachedDocument(InlineQueryResultDocumentOrCachedDocument),
#[serde(rename = "gif")]
CachedGif(InlineQueryResultCachedGif),
GifOrCachedGif(InlineQueryResultGifOrCachedGif),
#[serde(rename = "mpeg4_gif")]
CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif),
Mpeg4GifOrCachedMpeg4Gif(InlineQueryResultMpeg4GifOrCachedMpeg4Gif),
#[serde(rename = "photo")]
CachedPhoto(InlineQueryResultCachedPhoto),
PhotoOrCachedPhoto(InlineQueryResultPhotoOrCachedPhoto),
#[serde(rename = "sticker")]
CachedSticker(InlineQueryResultCachedSticker),
ayrat555 marked this conversation as resolved.
Show resolved Hide resolved
#[serde(rename = "video")]
CachedVideo(InlineQueryResultCachedVideo),
VideoOrCachedVideo(InlineQueryResultVideoOrCachedVideo),
#[serde(rename = "voice")]
CachedVoice(InlineQueryResultCachedVoice),
VoiceOrCachedVoice(InlineQueryResultVoiceOrCachedVoice),
#[serde(rename = "article")]
Article(InlineQueryResultArticle),
#[serde(rename = "audio")]
Audio(InlineQueryResultAudio),
#[serde(rename = "contract")]
Contact(InlineQueryResultContact),
#[serde(rename = "game")]
Game(InlineQueryResultGame),
#[serde(rename = "document")]
Document(InlineQueryResultDocument),
#[serde(rename = "gif")]
Gif(InlineQueryResultGif),
#[serde(rename = "location")]
Location(InlineQueryResultLocation),
#[serde(rename = "mpeg4_gif")]
Mpeg4Gif(InlineQueryResultMpeg4Gif),
#[serde(rename = "photo")]
Photo(InlineQueryResultPhoto),
#[serde(rename = "venue")]
Venue(InlineQueryResultVenue),
#[serde(rename = "video")]
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum InlineQueryResultAudioOrCachedAudio {
CachedAudio(InlineQueryResultCachedAudio),
Audio(InlineQueryResultAudio),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bunch of repetition 🤔

But also not that much that a macro might be really worth it. Can there be a generic type? Is that useful?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes. but I will be able to experiment on this only on weekend. you can push to this pr as well

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EdJoPaTo actually creating enum was easier than I thought. It seems you don't have to provide types for generics in enum 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the Either enum! Just not entirely sure how well it can be used in code. It also shows up randomly in the docs with not much docs so its kinda vague… Maybe naming it MaybeCached or something to clear up the intention of it?

Generally its used when creating the inline query results to be shown so the user knows whether its cached or not and picks one of them. So they know which struct to pick. Not sure how to improve the handling of that. Maybe with Into?


#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum InlineQueryResultDocumentOrCachedDocument {
CachedDocument(InlineQueryResultCachedDocument),
Document(InlineQueryResultDocument),
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum InlineQueryResultGifOrCachedGif {
CachedGif(InlineQueryResultCachedGif),
Gif(InlineQueryResultGif),
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum InlineQueryResultMpeg4GifOrCachedMpeg4Gif {
CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif),
Mpeg4Gif(InlineQueryResultMpeg4Gif),
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum InlineQueryResultPhotoOrCachedPhoto {
CachedPhoto(InlineQueryResultCachedPhoto),
Photo(InlineQueryResultPhoto),
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum InlineQueryResultVideoOrCachedVideo {
CachedVideo(InlineQueryResultCachedVideo),
Video(InlineQueryResultVideo),
#[serde(rename = "voice")]
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum InlineQueryResultVoiceOrCachedVoice {
CachedVoice(InlineQueryResultCachedVoice),
Voice(InlineQueryResultVoice),
}

Expand Down