Crates.io | ttrpc |
lib.rs | ttrpc |
version | 0.5.7 |
source | src |
created_at | 2019-09-23 07:19:30.426396 |
updated_at | 2023-10-24 09:07:41.130021 |
description | A Rust version of ttrpc. |
homepage | https://github.com/containerd/ttrpc-rust |
repository | https://github.com/containerd/ttrpc-rust |
max_upload_size | |
id | 166925 |
size | 127,334 |
ttrpc-rust is a non-core subproject of containerd
ttrpc-rust
is the Rust version of ttrpc. ttrpc is GRPC for low-memory environments.
The ttrpc compiler of ttrpc-rust
ttrpc_rust_plugin
is modified from gRPC compiler of gRPC-rs grpcio-compiler.
protoc
commandTo generate the sources from proto files:
Install protoc from github.com/protocolbuffers/protobuf
Install protobuf-codegen
cargo install --force protobuf-codegen
cd ttrpc-rust/compiler
cargo install --force --path .
$ protoc --rust_out=. --ttrpc_out=. --plugin=protoc-gen-ttrpc=`which ttrpc_rust_plugin` example.proto
API to generate .rs files to be used e. g. from build.rs.
Example code:
fn main() {
protoc_rust_ttrpc::Codegen::new()
.out_dir("protocols")
.inputs(&[
"protocols/protos/agent.proto",
])
.include("protocols/protos")
.rust_protobuf() // also generate protobuf messages, not just services
.run()
.expect("Codegen failed.");
}
ttrpc-rust supports async/.await. By using async/.await you can reduce the overhead and resource consumption caused by threads.
Currently we only support generating async codes by using ttrpc-codegen
ttrpc_codegen::Codegen::new()
.out_dir("protocols/asynchronous")
.inputs(&protos)
.include("protocols/protos")
.rust_protobuf()
.customize(Customize {
async_all: true, // It's the key option.
..Default::default()
})
.run()
.expect("Gen async codes failed.");
Provide customize option
async_all
: generate async codes for both server and clientasync_server
: generate async codes for serverasync_client
: generate async codes for clientSee more in
example/build.rs
Please follow the guidlines in example/async-server.rs
and example/async-client.rs
Go to the directory
$ cd ttrpc-rust/example
Start the server
$ cargo run --example server
or
$ cargo run --example async-server
Start a client
$ cargo run --example client
or
$ cargo run --example async-client
protobuf-codegen, ttrpc_rust_plugin and your code should use the same version protobuf. You will get following fail if use the different version protobuf.
27 | const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_0;
| ^^^^^^^^^^^^^ help: a constant with a similar name exists: `VERSION_2_10_1`
The reason is that files generated by protobuf-codegen are compatible only with the same version of runtime
To fix this issue:
cd grpc-rs
cargo clean
cargo update
cargo install --force protobuf-codegen
cd ttrpc-rust/compiler
cargo clean
cargo update
cargo install --force --path .