Skip to content

Instantly share code, notes, and snippets.

View allengeorge's full-sized avatar

Allen George allengeorge

View GitHub Profile
@allengeorge
allengeorge / server.rs
Last active May 8, 2017 00:47
Rust Thrift Example (server.rs)
extern crate thrift;
extern crate example;
use thrift::protocol::{TCompactInputProtocolFactory, TCompactOutputProtocolFactory};
use thrift::transport::{TFramedReadTransportFactory, TFramedWriteTransportFactory};
use thrift::server::TServer;
use example::{SimpleServiceSyncHandler, SimpleServiceSyncProcessor};
fn main() {
@allengeorge
allengeorge / client.rs
Last active March 22, 2020 09:09
Rust Thrift Example (client.rs)
extern crate thrift;
extern crate example;
use thrift::protocol::{TCompactInputProtocol, TCompactOutputProtocol};
use thrift::transport::{TFramedReadTransport, TFramedWriteTransport, TIoChannel, TTcpChannel};
use example::{SimpleServiceSyncClient, TSimpleServiceSyncClient};
fn main() {
match run() {
@allengeorge
allengeorge / lib.rs
Created May 7, 2017 18:18
Rust Thrift Example (lib.rs)
extern crate thrift;
extern crate ordered_float;
extern crate try_from;
mod simple_service;
pub use simple_service::*;
@allengeorge
allengeorge / Cargo.toml
Created May 7, 2017 18:04
Rust Thrift Example (Cargo.toml)
[package]
name = "example"
version = "0.0.1"
publish = false
[dependencies]
env_logger = "0.4.0"
log = "0.3.7"
ordered-float = "0.3.0"
try_from = "0.2.0"
@allengeorge
allengeorge / simple_service.thrift
Last active May 7, 2017 17:59
Rust Thrift Example IDL
service SimpleService {
string hello(1: string name)
}
@allengeorge
allengeorge / compiler_error
Created April 29, 2017 16:22
compiler_error
Compiling thrift v1.0.0 (file:///Users/allen/src/rust_projects/thrift/lib/rs)
Compiling thrift-test v0.1.0 (file:///Users/allen/src/rust_projects/thrift/test/rs)
error[E0277]: the trait bound `thrift::server::TProcessor + std::marker::Send + 'static: std::marker::Sync` is not satisfied
--> src/bin/test_server.rs:129:30
|
129 | let mut server = TServer::new(
| ^^^^^^^^^^^^ the trait `std::marker::Sync` is not implemented for `thrift::server::TProcessor + std::marker::Send + 'static`
|
= note: `thrift::server::TProcessor + std::marker::Send + 'static` cannot be shared between threads safely
= note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique<thrift::server::TProcessor + std::marker::Send + 'static>`
@allengeorge
allengeorge / sized.rs
Created April 26, 2017 23:20
Sized Blanket Impls
impl<T> TReadTransport for T
where
T: Read + ?Sized,
{
}
impl<T> TReadTransport for Box<T>
where
T: Read + ?Sized,
{
To learn more, run the command again with --verbose.
allen@mrwiggles ~/s/r/t/l/rs> cargo test
Compiling thrift v1.0.0 (file:///Users/allen/src/rust_projects/thrift/lib/rs)
error[E0308]: mismatched types
--> src/protocol/multiplexed.rs:200:16
|
200 | mem_fn(&mut chan, |c| assert_eq!(c.write_bytes(), &expected));
| ^^^^^^^^^ expected trait transport::TIOChannel, found struct `transport::mem::TBufferChannel`
|
= note: expected type `&mut std::boxed::Box<transport::TIOChannel + 'static>`
allen@mrwiggles ~/s/r/t/l/rs> cargo build
Compiling thrift v1.0.0 (file:///Users/allen/src/rust_projects/thrift/lib/rs)
error[E0277]: the trait bound `transport::TTransportFactory + 'static: std::marker::Send` is not satisfied
--> src/server/threaded.rs:160:34
|
160 | let handle = thread::spawn(move || handle_incoming_connection(&mut self.processor, i_prot, o_prot));
| ^^^^^^^^^^^^^ the trait `std::marker::Send` is not implemented for `transport::TTransportFactory + 'static`
|
= note: `transport::TTransportFactory + 'static` cannot be sent between threads safely
= note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<transport::TTransportFactory + 'static>`
@allengeorge
allengeorge / compile_error
Created April 11, 2017 00:33
Lifetime failures
allen@mrwiggles ~/s/r/t/l/rs> cargo build
Compiling thrift v1.0.0 (file:///Users/allen/src/rust_projects/thrift/lib/rs)
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
--> src/server/threaded.rs:160:29
|
160 | let p = &mut self.processor; // FIXME: why can't I inline this?
| ^^^^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 154:67...
--> src/server/threaded.rs:154:68