Make context mutable!

This commit is contained in:
Fabian Stamm
2026-02-02 14:37:08 +01:00
parent 8204870bf5
commit 078e8d1829
2 changed files with 6 additions and 6 deletions

View File

@@ -159,7 +159,7 @@ impl RustCompiler {
)
})
.collect::<Vec<String>>();
params.push("ctx: &Self::Context".to_string());
params.push("ctx: &mut Self::Context".to_string());
let params = params.join(", ");
let ret = method
@@ -218,7 +218,7 @@ impl RustCompiler {
f.a1("#[allow(non_snake_case)]");
f.a1(
"async fn handle(&self, msg: &JRPCRequest, function: &str, ctx: &Self::Context) -> Result<(bool, Value)> {",
"async fn handle(&self, msg: &JRPCRequest, function: &str, ctx: &mut Self::Context) -> Result<(bool, Value)> {",
);
f.a2("match function {");

View File

@@ -112,7 +112,7 @@ pub trait JRPCServerService: Send + Sync {
&self,
request: &JRPCRequest,
function: &str,
ctx: &Self::Context,
ctx: &mut Self::Context,
) -> Result<(bool, Value)>;
}
@@ -165,12 +165,12 @@ impl<Context: Send + Sync + 'static> JRPCSession<Context> {
pub fn handle_request(&self, request: JRPCRequest, ctx: Context) -> () {
let session = self.clone();
tokio::task::spawn(async move {
let context = ctx;
session.handle_request_awaiting(request, &context).await;
let mut context = ctx;
session.handle_request_awaiting(request, &mut context).await;
});
}
pub async fn handle_request_awaiting(&self, request: JRPCRequest, ctx: &Context) -> () {
pub async fn handle_request_awaiting(&self, request: JRPCRequest, ctx: &mut Context) -> () {
info!("Received request: {}", request.method);
trace!("Request data: {:?}", request);
let method: Vec<&str> = request.method.split('.').collect();