Trying building app with alcro as ui
and rocket as backend.
In the ui
trying to bind a button
with exit
command, so that both ui
and server
are closed upon the press of exit
button, but stuck with move
restrictions, any thought?
#![feature(decl_macro, proc_macro_hygiene)]
mod routes;
use rocket_contrib::serve::StaticFiles;
use rocket_contrib::templates::Template;
use std::sync::Arc;
use alcro::{UI, UIBuilder, Content, JSObject};
use std::thread::spawn;
use std::process::exit;
struct Chrome(Arc<UI>); // to be used in rocket routes by
fn main() {
println!("Hello, world!");
let ui = Arc::new(
UIBuilder::new()
.content(Content::Url("http://localhost:8000"))
.size(1200, 800)
.run()
);
ui.bind("exit", move |_| { // ui value moved into closure
println!("good bye");
ui.close(); // ui variable moved due to use in closure
exit(0);
Ok(JSObject::Null)
});
rocket::ignite()
.attach(Template::fairing())
.mount("/static",
StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR", "/static"))))
.mount("/", rocket::routes![routes::root::root])
.manage(Chrome(ui)) // ui value used here after move
.launch();
}
Got the below error:
error[E0382]: borrow of moved value: `ui`
--> src\main.rs:35:24
|
16 | let ui = Arc::new(
| -- move occurs because `ui` has type `std::sync::Arc<alcro::UI>`, which does not implement the `Copy` trait
...
23 | ui.bind("exit", move |_| { // ui value moved into closure
| -------- value moved into closure here
24 | println!("good bye");
25 | ui.close(); // ui variable moved due to use in closure
| -- variable moved due to use in closure
...
35 | .manage(Chrome(ui.clone())) // ui value used here after move
| ^^ value borrowed here after move