Crates.io | puroro |
lib.rs | puroro |
version | 0.14.0 |
source | src |
created_at | 2021-10-05 20:08:28.610109 |
updated_at | 2023-03-19 18:16:12.108734 |
description | A Rust implementation of Google Protocol Buffer. |
homepage | |
repository | https://github.com/wada314/puroro |
max_upload_size | |
id | 460826 |
size | 821,759 |
A yet another protocol buffer compiler implementation for Rust language. This project is licensed under Apache 2.0 license.
This is not an officially supported Google product.
See puroro/src/lib.rs for more documents.
This library is under development and it is very possible to make breaking changes.
Currently this library only supports Rust nightly channel.
First, let's create a crate for your .proto files (and the generated .rs files). Actually it is not required to create a separated crate for the proto files, though I recommend to make it to avoid any unexpected problems.
$ cargo new my-examples --lib
$ cd my-examples
# Create your .proto files under this directory
$ mkdir protos
# Edit your .proto files
$ emacs-vim-nano-or-whatever ./protos/yourproto.proto
As an example, let's make a simple proto file test1.proto
:
syntax = "proto3";
package library;
message Book {
string title = 1;
uint32 num_pages = 2;
}
Note that the file names does not make any effect in the generated codes.
Only the package name (in this case, package library;
) makes the effect
to the generated code's module name (or file name).
Then edit the Cargo.toml
to add the dependency to puroro
library crates:
[dependencies]
puroro = "*"
[build-dependencies]
puroro-codegen = "*"
protoc-bin-vendored = "3.0.0"
As a last step, create a file build.rs
under the crate root directory.
Check our sample build.rs and just copy and paste.
Once you have finished these steps, the directory should be like this:
+ my-examples/
├ src/
│ └ (empty)
├ protos/
│ └ test1.proto
├ cargo.toml
├ build.rs
├ (some other generated files)
Then run cargo build
command. If it successfully runs, then the generated
.rs
files will be generated under src/
directory and you can use it from
your own crate. Congraturations!
optional int32 foo = 1; [default=10]
)allocator_api
...Default::default()
syntax.