[][src]Trait prost_build::ServiceGenerator

pub trait ServiceGenerator {
    fn generate(&mut self, service: Service, buf: &mut String);

    fn finalize(&mut self, _buf: &mut String) { ... }
}

A service generator takes a service descriptor and generates Rust code.

ServiceGenerator can be used to generate application-specific interfaces or implementations for Protobuf service definitions.

Service generators are registered with a code generator using the Config::service_generator method.

A viable scenario is that an RPC framework provides a service generator. It generates a trait describing methods of the service and some glue code to call the methods of the trait, defining details like how errors are handled or if it is asynchronous. Then the user provides an implementation of the generated trait in the application code and plugs it into the framework.

Such framework isn't part of Prost at present.

Required methods

fn generate(&mut self, service: Service, buf: &mut String)

Generates a Rust interface or implementation for a service, writing the result to buf.

Loading content...

Provided methods

fn finalize(&mut self, _buf: &mut String)

Finalizes the generation process.

In case there's something that needs to be output at the end of the generation process, it goes here. Similar to generate, the output should be appended to buf.

An example can be a module or other thing that needs to appear just once, not for each service generated.

This still can be called multiple times in a lifetime of the service generator, because it is called once per .proto file.

The default implementation is empty and does nothing.

Loading content...

Implementors

Loading content...