Crates.io | tonic-codec-protobuf |
lib.rs | tonic-codec-protobuf |
version | 0.1.0 |
source | src |
created_at | 2024-06-02 15:25:05.278846 |
updated_at | 2024-06-02 15:25:05.278846 |
description | A tonic::Codec that implements `application/grpc+proto` via the rust-protobuf. |
homepage | https://github.com/overvenus/tonic-protobuf |
repository | https://github.com/overvenus/tonic-protobuf |
max_upload_size | |
id | 1259278 |
size | 10,436 |
Compiles proto files via rust-protobuf and generates service stubs for use with tonic.
Required dependencies
[dependencies]
tonic = "<tonic-version>"
protobuf = "<protobuf-version>"
tonic-codec-protobuf = "<tonic-codec-protobuf-version>"
[build-dependencies]
tonic-build-protobuf = "<tonic-build-protobuf-version>"
In build.rs
:
fn main() {
// Project layout:
// .
// ├── Cargo.toml
// ├── build.rs
// ├── include
// │ └── rustproto.proto
// ├── proto
// │ └── debugpb.proto
// └── src
// └── lib.rs
tonic_build_protobuf::Builder::new()
.out_dir(format!(
"{}/protos",
std::env::var("OUT_DIR").expect("No OUT_DIR defined")
))
.proto_path("crate")
.file_name(|pkg, svc| format!("{pkg}_{svc}_tonic"))
.codec_path("::tonic_codec_protobuf::ProtobufCodecV3")
.compile(&["proto/debugpb.proto"], &["proto", "include"]);
}
Then you can reference the generated Rust like this this in your code:
mod generated {
include!(concat!(env!("OUT_DIR"), "debugpb_debug_tonic.rs"));
}
pub use generated::*;
See examples here
This project is licensed under the MIT license.