Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Borrowed data escapes outside of my function
I get the following error which I don't understand and how to fix it
error[E0521]: borrowed data escapes outside of method
--> src/websocket/websocket.rs:154:9
|
64 | fn started(&mut self, ctx: &mut Self::Context) {
| ---------
| |
| `self` is a reference that is only valid in the method body
| let's call the lifetime of this reference `'1`
...
154 | / ctx.run_interval(DURATION, move |_, ctx| {
155 | | let time = Local::now();
156 | | let timestamp = time.timestamp();
157 | | let req = handle_messages::get_req();
... |
197 | | });
| | ^
| | |
| |__________`self` escapes the method body here
| argument requires that `'1` must outlive `'static`
For more information about this error, try `rustc --explain E0521`.
for this function part
ctx.run_interval(DURATION, move |_, ctx| {
let time = Local::now();
let timestamp = time.timestamp();
let req = handle_messages::get_req();
if timestamp <= expired {
match req.path() {
STUDENT_BLACKLIGHT => {
let data = send_message(BLACKLIGHT_TOPIC);
ctx.text(data.to_string());
reset_path()
},
MISSION_PATH => {
let data = send_message(MISSION_STATUS);
ctx.text(data.to_string());
if self.role.contains(&STUDENT_ROLE.to_string()) {
handle_messages::set_req(TEACHER_MISSION_NOTIFICATION.parse::<Uri>().unwrap());
} else {
reset_path()
}
},
LEARNING_UNIT_PATH => {
let data = send_message(LEARNING_UNIT_STATUS);
ctx.text(data.to_string());
if self.role.contains(&STUDENT_ROLE.to_string()) {
handle_messages::set_req(TEACHER_LU_NOTIFICATION.parse::<Uri>().unwrap());
} else {
reset_path();
}
},
_ => {}
}
} else {
let msg = String::from("Connection closed");
let data = Message::new(CONNECTION_TOPIC.to_string(), msg);
ctx.text(data.to_string());
ctx.stop()
}
});
9 posts - 3 participants
🏷️ rust_feed