Skip to content
forked from tokio-rs/prost

PROST! a Protocol Buffers implementation for the Rust Language

License

Notifications You must be signed in to change notification settings

KaiserKarel/prosit

 
 

Repository files navigation

continuous integration

PROSIT

prosit is a Protocol Buffers implementation for the Rust Language, based on prost. prosit extends prost with different code generation options, adding more idiomatic Rust types according to the parse, don't validate philosophy.

To add prosit to your project as an alternative code generator, use the patch feature of cargo, and use prost inside your codebase.

[dependencies]
prost = "0.7"
uuid = "0.8"

[build-dependencies]
tonic-build = { version = "0.4" }

[patch.crates-io]
prost = { git = 'https://github.com/kaiserkarel/prosit' }
prost-derive = { git = 'https://github.com/kaiserkarel/prosit' }
prost-types = { git = 'https://github.com/kaiserkarel/prosit' }
prost-build = { git = 'https://github.com/kaiserkarel/prosit' }

Once prosit exits experimental stage, it will be published on Cargo, but hopefully as an extension to prost

Codegen

Include rust.proto in your protobufs (by copying the file, or vendoring prosit). You can then use the custom codegen options.

syntax = "proto3";

package proto.api.v1;

import "api/rust.proto";

message Data {
  // generates the Uuid type instead of the string type
  string id = 1 [(rust.codegen).type = UUID];
  
  // does not wrap Foo in an option, but instead errors during parsing if foo is missing.
  Foo foo = 2 [(rust.codegen).required = true];
  
  // generates the url type.
  string url = 3 [(rust.codegen).type = URL];
}

message Foo {
  oneof biz {
    option (rust.required) = true;

    string bar = 1;
    string bax = 2;
  }
}

This wil generate approximately the following code:

pub struct Data {
   id: ::uuid::Uuid,
   foo: Foo,
   url: ::url::Url,
}

pub struct Foo {
  biz: Biz,
}

pub enum Biz {
  Bar(String),
  Baz(String),
}

About

PROST! a Protocol Buffers implementation for the Rust Language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 99.5%
  • Other 0.5%