1

My plugin configuration is quite large, and I don't want to clone the plugin configuration every time When I create an httpContext. Can I use Rc::clone() inside Wasm? (Is it may cause memory leak? Im sorry not good at rust) . Or is there any other way for me to get the plugin configuration saved in RootContext from httpContext while avoiding cloning all the data?

struct HttpHeadersRoot {
    wasm_configuration: Rc<WasmConfiguration>,
}

impl RootContext for HttpHeadersRoot {
    fn get_type(&self) -> Option<ContextType> {
        Some(ContextType::HttpContext)
    }

   fn on_configure(&mut self, _: usize) -> bool {
        if let Some(config_bytes) = self.get_plugin_configuration() {
            if str::from_utf8(&config_bytes).is_err() {
                return false;
            }
            let t: WasmConfiguration = serde_json::from_str(str::from_utf8(&config_bytes).unwrap()).unwrap();
            self.wasm_configuration = Rc::new(t);
            return true
        } else {
            return false;
        }
    }

    fn create_http_context(&self, _: u32) -> Option<Box<dyn HttpContext>> {
        Some(Box::new(HttpHeaders {
            wasm_configuration: Rc::clone(&self.wasm_configuration),
        }))
    }
}

I want someone can give me the right way or code.

0 Answers0