Skip to content

Instantly share code, notes, and snippets.

@lattenwald
Last active August 24, 2018 10:30
Show Gist options
  • Save lattenwald/e76bb01f44f86b0645ffd47999c7e5de to your computer and use it in GitHub Desktop.
Save lattenwald/e76bb01f44f86b0645ffd47999c7e5de to your computer and use it in GitHub Desktop.
extern crate libc;
use libc::{c_double, c_void};
use std::os::raw::c_char;
#[derive(Debug)]
pub struct Tdlib {
instance: *mut c_void
}
#[link(name = "tdjson")]
extern {
fn td_json_client_create() -> *mut c_void;
fn td_json_client_destroy(client: *mut c_void);
}
impl Tdlib {
pub fn create() -> Self {
let client = unsafe { td_json_client_create() };
Tdlib { instance: client }
}
}
impl Drop for Tdlib {
fn drop(&mut self) {
unsafe {
println!("dropping client");
td_json_client_destroy(self.instance);
}
}
}
extern crate rust_tdlib;
use rust_tdlib::Tdlib;
fn main() {
println!("Hello, world!");
{
let client = Tdlib::create();
println!("client: {:?}", client);
//XXX drops!
}
println!("ok")
}
# Now there's some tdlib debug output
13:24:45 qalex@qxps:~/projects/rust/rust-tdlib git [master*]
% cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/rust-tdlib`
Hello, world!
client: Tdlib { instance: 0x7f951b840000 }
dropping client
[ 3][t 4][1535106288.587110758][Td.cpp:4633][!Td][&td_requests] Sending update: updateAuthorizationState {
authorization_state = authorizationStateWaitTdlibParameters {
}
}
[ 2][t 4][1535106288.587305546][Td.cpp:4215][!Td] ON_CLOSED
[ 3][t 4][1535106288.587322950][Td.cpp:4633][!Td][&td_requests] Sending update: updateAuthorizationState {
authorization_state = authorizationStateClosed {
}
}
ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment