Automatically generate jsonrpsee Trait for auto-generated prost types.
```toml [dependencies] pbjson = "0.3" pbjson-types = "0.3" prost = "0.10" prost-types = "0.10"
[build-dependencies] pbjson-build = "0.3" pbjsonrpc-build = "0" prost-build = "0.10" ```
Next create a build.rs
containing the following
```rust,ignore let root = PathBuf::from(env!("CARGOMANIFESTDIR")).join("protos"); let proto_files = vec![root.join("myproto.proto")];
// Tell cargo to recompile if any of these proto files are changed for protofile in &protofiles { println!("cargo:rerun-if-changed={}", proto_file.display()); }
let descriptorpath = PathBuf::from(env::var("OUTDIR").unwrap()) .join("proto_descriptor.bin");
prostbuild::Config::new() // Save descriptors to file .filedescriptorsetpath(&descriptorpath) // Override prost-types with pbjson-types .compilewellknowntypes() .externpath(".google.protobuf", "::pbjsontypes") // Generate prost structs .compileprotos(&protofiles, &[root])?;
let descriptorset = std::fs::read(descriptorpath)?; pbjsonbuild::Builder::new() .registerdescriptors(&descriptorset)? .build(&[".mypackage"])?; pbjsonrpcbuild::Builder::new() .registerdescriptors(&descriptorset)? .build(&[".mypackage"])?; ```
Finally within lib.rs
rust,ignore
/// Generated by [`prost-build`]
include!(concat!(env!("OUT_DIR"), "/mypackage.rs"));
/// Generated by [`pbjson-build`]
include!(concat!(env!("OUT_DIR"), "/mypackage.serde.rs"));
/// Generated by [`pbjsonrpc-build`]
include!(concat!(env!("OUT_DIR"), "/mypackage.jsonrpc.rs"));