How to use / example comments
There is shadow-clone = "0.1"
in How to use
section in the README.md
(also on crates.io). I think there should be version 1.0.0
now.
The example from the README:
let s = "foo".to_string();
let c = move |x: i32| format!("{}{}", s, x);
let bar = s;
- The code block has flags
rust,compile_fail
- it breaks syntax highlighting in GitHub / crates.io. I don't know if it's copy/paste error or it has to be there. - I would rather use
enc!
macro from enclose library for this case. E.g.:
let s = "foo".to_string();
let c = enc!((s) move |x: i32| format!("{}{}", s, x));
let bar = s;
- But it's useful for other cases - copy/pasted example from WIP proxy based on hyper:
let service = service_fn({
shadow_clone!(db);
move |req: Request<Body>| {
shadow_clone!((mut) config_receiver, client, schedule_config_reload, db);
async move {
on_request(
req,
client,
config_receiver.recv().await.expect("receive proxy config"),
schedule_config_reload,
db,
).await
}
}
});
Note: See enclose library once more time - it's possible to use mut
without parentheses (mut)
. Maybe there are lucky or they found a way how to to that - just tip for further exploration.
Thank you! I'll use this lib in my projects and maybe you'll find it also in Seed :)