I'm trying to add new member variables to a struct in an impl block.
I'm using protoc-rust to procedurally generate Rust code from protocol buffers. In particular, it generates structs and methods for the messages defined in the protos. I need to add new members to these structs to initialize some WebAssembly::Instance
s off of a bytes object in the struct
The struct:
pub struct Module {
// message fields
pub module_name: ::std::string::String,
pub init_script: ::std::string::String,
pub JS_boiler_plate: ::std::string::String,
pub functions: ::protobuf::RepeatedField<Function>,
pub meta_data: ::std::string::String,
pub packager: ::std::string::String,
pub pure_wasm: bool,
pub wasm_binary: ::std::vec::Vec<u8>,
// special fields
pub unknown_fields: ::protobuf::UnknownFields,
pub cached_size: ::protobuf::CachedSize,
}
What I want to do:
impl RPC_Module::Module {
self.wasm_instance: WebAssembly::Instance;
pub fn init(&mut self) -> Result<(), &'static str> {
// Init the instance based off of wasm_binary
let self.wasm_instance = WebAssembly::Instance::new()
}
}
What I get:
Compiling wRPC v0.1.0 (/Users/swarfield/Code/wRPC-Core/w-rpc-core)
error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `let`
--> src/protos/mod.rs:12:5
|
11 | impl RPC_Module::Module {
| - expected one of 11 possible tokens here
12 | let self.wasm_instance: WebAssembly::Instance;
| ^^^ unexpected token