rtdlib
is TDLib for rust.
rtdlib
crate have TDLib type (classes). and tdjson
binding. not have client api. if use rtdlib
you need include libtdjson.so
to you build path.
rtdlib
include a prebuilt td types, you can check types. The version of >0.3.0
not provide build code before run this crate, last support version is 0.2.1, if want generate types from telegram official document you can check generate project.
When build from official document, rtdlib will generate a td schema file, but this file not include in cargo package, if you need use this file, you need check schema.toml.
BUILD TYPE.RS IS SLOWLY.
Notice
rtdlib
build td type, use telegram official document, https://core.telegram.org/tdlib/docs/td_api8h.html .
So there is a possibility of compilation failure.
It depends on whether the document has changed.
When rtdlib is stable, the use of code generation is not recommended.
toml
[dependencies]
rtdlib = "0.3"
rust
let json = r#"{"@type":"updateAuthorizationState","@struct":"UpdateAuthorizationState","authorization_state":{"@type":"authorizationStateWaitTdlibParameters","@struct":"AuthorizationStateWaitTdlibParameters"}}"#;
let state: UpdateAuthorizationState = serde_json::from_str(&json[..]).expect("Json fail");
assert_eq!("updateAuthorizationState", state.td_name());
rust
use rtdlib::tdjson::Tdlib;
let tdlib = Tdlib::new();
let request = r#"{"@type": "getMe"}"#;
tdlib.send(request);
and more document you need check telegram api
How include libtdjson.so
The first you need read td know how to build td.
And then, when you have libtdjson.so
copy this file to /usr/lib
.
Or set an environment
bash
export RUSTFLAGS="-C link-args=-Wl,-rpath,/path/to/libtdjson.so"
cargo run
In the development phase, you can set RUSTFLAGS
environment to you IDE.