rust-protobuf
Protobuf implementation in Rust.
- Written in pure rust
- Generate rust code
- Has runtime library for generated code (Coded{Input|Output}Stream impl)
How to use rust-protobuf
- Install protobuf for
protoc
binary.
On OS X Homebrew can be used:
brew install protobuf
On Ubuntu, protobuf-compiler
package can be installed:
apt-get install protobuf-compiler
Protobuf is needed only for code generation, rust-protobuf
runtime
does not use protobuf
library.
- Install
protoc-gen-rust
program (which isprotoc
plugin)
It can be installed either from source or with cargo install protobuf
command.
- Add
protoc-gen-rust
to $PATH
If you installed it with cargo, it should be
PATH="$HOME/.cargo/bin:$PATH"
- Generate .rs files:
protoc --rust_out . foo.proto
This will generate .rs files in current directory.
- Add rust-protobuf as dependency to your project
Cargo.toml
:
[dependencies.protobuf]
- Include generated files into your project .rs file:
extern crate protobuf; // depend on rust-protobuf runtime
mod foo; // add generated file to the project
Generated code
Have a look at generated files, used internally in rust-protobuf:
- descriptor.rs for descriptor.proto (that is part of Google protobuf)
TODO
- Implement some rust-specific options
- Deal better with namespaces
- Protobuf reflection
- Extensions
- Generate stubs for services