Rust Compilation failed

use std::sync::Arc;

use axum::Json;

use dashmap::{DashMap};

use lazy_static::lazy_static;

use serde_json::{json, Value};

pub trait testServer {
fn getOneBronAndCamp(&mut self) ->Json;
}

pub struct RoomServer{
pub BattleTime:f32,
pub sceneId:String,
}

impl testServer for RoomServer{

fn getOneBronAndCamp(&mut self) ->Json {

Json(json!({ "camp": 1, "pos":{"x":30.0, "y":self.BattleTime, "z":60.5}, "index":2}))

}

}

lazy_static!{

pub static ref roomList:Arc<DashMap<String, RoomServer>> = Arc::new(DashMap::new());

}

fn main() {

roomList.insert(String::from("1") , RoomServer { BattleTime: 10.5, sceneId: String::from("852963") });

roomList.insert(String::from("2") , RoomServer { BattleTime: 10.7, sceneId: String::from("741852") });

roomList.insert(String::from("3") , RoomServer { BattleTime: 10.6, sceneId: String::from("753159") });

for item in roomList.iter() {

println!("{}", item.value().sceneId);

}

let v = roomList.get("1");

let binding = v.unwrap();

let roomServer = binding.value();

let info = roomServer.getOneBronAndCamp();

loop {

}

}

Please put code between

```rust

and

```

Also could you post the full error message. That makes it easier to help you without having to compile it ourself.

That error is saying if you want to call getOneBronAndCamp() (a method taking &mut self), your roomServer variable needs to be an &mut RoomServer.

Keep in mind that DashMap is a concurrent data structure, so it will only hand out shared (&) references. Wrap your RoomServer in a std::sync::Mutex and call the lock() method if you need to update it (i.e. pub static ref roomList:Arc<DashMap<String, Mutex<RoomServer>>>).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.