Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/overvenus/tonic-protobuf
Codegen module of `tonic` gRPC implementation with rust-protobuf.
https://github.com/overvenus/tonic-protobuf
Last synced: 2 months ago
JSON representation
Codegen module of `tonic` gRPC implementation with rust-protobuf.
- Host: GitHub
- URL: https://github.com/overvenus/tonic-protobuf
- Owner: overvenus
- License: mit
- Created: 2024-06-02T11:00:53.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-02T15:46:37.000Z (7 months ago)
- Last Synced: 2024-09-17T23:58:22.706Z (3 months ago)
- Language: Rust
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tonic-build-protobuf / tonic-codec-protobuf
[![Crates.io](https://img.shields.io/crates/v/tonic-build-protobuf)](https://crates.io/crates/tonic-build-protobuf)
[![Documentation](https://docs.rs/tonic-build-protobuf/badge.svg)](https://docs.rs/tonic-build-protobuf)
[![LICENSE](https://img.shields.io/crates/l/tonic-build-protobuf)](LICENSE)Compiles proto files via [rust-protobuf](https://crates.io/crates/protobuf) and generates service stubs for use with tonic.
## Features
Required dependencies
```toml
[dependencies]
tonic = ""
protobuf = ""
tonic-codec-protobuf = ""[build-dependencies]
tonic-build-protobuf = ""
```## Examples
In `build.rs`:
```rust,ignore
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:
```rust,ignore
mod generated {
include!(concat!(env!("OUT_DIR"), "debugpb_debug_tonic.rs"));
}pub use generated::*;
```See [examples here](https://github.com/overvenus/tonic-protobuf/tree/master/examples)
## License
This project is licensed under the [MIT license](https://github.com/overvenus/tonic-protobuf/blob/main/LICENSE).