[][src]Struct exonum_build::ProtobufGenerator

pub struct ProtobufGenerator<'a> { /* fields omitted */ }

Generates Rust modules from Protobuf files.

The protoc executable (i.e., the Protobuf compiler) should be in $PATH.

Examples

Specify in the build script (build.rs) of your crate:

use exonum_build::ProtobufGenerator;

ProtobufGenerator::with_mod_name("example_mod.rs")
    .with_input_dir("src/proto")
    .with_crypto()
    .with_common()
    .with_merkledb()
    .generate();

After the successful run, $OUT_DIR will contain a module for each Protobuf file in src/proto and example_mod.rs which will include all generated modules as submodules.

To use the generated Rust types corresponding to Protobuf messages, specify in src/proto/mod.rs:

This example is not tested
include!(concat!(env!("OUT_DIR"), "/example_mod.rs"));

// If you use types from `exonum` .proto files.
use exonum::proto::schema::*;

Methods

impl<'a> ProtobufGenerator<'a>[src]

pub fn with_mod_name(mod_name: &'a str) -> Self[src]

Name of the rust module generated from input proto files.

Panics

If the mod_name is empty.

pub fn with_input_dir(self, path: &'a str) -> Self[src]

A directory containing input protobuf files. For single mod_name you can provide only one input directory, If proto-files in the input directory have dependencies located in another directories, you must specify them using add_path method.

Predefined dependencies can be specified using corresponding methods with_common, with_crypto, with_exonum.

Panics

If the input directory is already specified.

pub fn add_path(self, path: &'a str) -> Self[src]

An additional directory containing dependent proto-files, can be used multiple times.

pub fn with_common(self) -> Self[src]

Common types for all crates.

pub fn with_crypto(self) -> Self[src]

Proto files from exonum-crypto crate (Hash, PublicKey, etc.).

pub fn with_merkledb(self) -> Self[src]

Proto files from exonum-merkledb crate (MapProof, ListProof).

pub fn with_exonum(self) -> Self[src]

Exonum core related proto files,

pub fn with_includes(self, includes: &'a [ProtoSources]) -> Self[src]

Add multiple include directories.

pub fn without_sources(self) -> Self[src]

Switches off inclusion of source Protobuf files into the generated output.

pub fn generate(self)[src]

Generate proto files from specified sources.

Panics

If the input_dir or includes are empty.

Trait Implementations

impl<'a> Debug for ProtobufGenerator<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for ProtobufGenerator<'a>

impl<'a> Send for ProtobufGenerator<'a>

impl<'a> Sync for ProtobufGenerator<'a>

impl<'a> Unpin for ProtobufGenerator<'a>

impl<'a> UnwindSafe for ProtobufGenerator<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,