Lonami / grammers

(tele)gramme.rs - use Telegram's API from Rust
https://t.me/gramme_rs
Apache License 2.0
561 stars 116 forks source link

Feature request: serde support #276

Closed RuofengX closed 1 month ago

RuofengX commented 1 month ago

I am using this awesome crate in my actual work to gather some useful information from open chats and bots.

I want to save the data to database or just simple json-string, like

I found this project seems doesn't support serde, am I right? And if it really not support, why? I noticed that telegram has it's own bytecode ser&de function, but serde is the in-facts standard in rust language. Using serde framework will make this project more flexible.

Lonami commented 1 month ago

I'm okay adding it behind a feature gate. If you're willing to send a PR, you would need to modify the generator to emit the derive, but I suppose that would be enough.

Be warned though, it's a lot of generated code, and I suspect serde will bloat it even further, which is why I've avoided it so far.

And of course appreciate the compliments :)

RuofengX commented 1 month ago

Thanks for reply.

I didn't notice such structure is generated. Is that done by grammers-tl-gen?
I am looking into grammers-tl-gen module, it works like macros but it directly generate code files. How it works?

Lonami commented 1 month ago

The generator is used by grammers-tl-types' build.rs script.

RuofengX commented 1 month ago

How often does build.rs run? Is it just a oneshot task? Or does telegram official often change the tl schema?

So is it possible to simply add #[derive(Serialize, Deserialized)] in generated files?

Lonami commented 1 month ago

build.rs runs when its crate or the dependencies of its crate change. So changing the api.tl, the generator, or the types package itself, should cause it to re-run.

telegram official often change the tl schema

Pretty regularly, yes. But grabbing the latest api.tl is a manual task.