Instead of this:
fn some_wlroots_callback(output_handle: OutputHandle,
surface_handle: SurfaceHandle) {
output_handle.run(|output| {
surface_handle.run(|surface| {
// maybe some more nested layers...
}).unwrap()
}).unwrap()
}
One can do this: fn some_wlroots_callback(
ctx: CallbackContext,
output_handle: OutputHandle,
surface_handle: SurfaceHandle
) {
let output = ctx.get(output_handle);
let surface = ctx.get(surface_handle);
}
This is safe, because the lifetime of "output" and "surface" can be bound to the lifetime of the "ctx" (whose lifetime is controlled by the library: the library simply has to make sure that "ctx" is not accessible outside of a callback).edit: Realised you can't tell that there's an implicit lifetime in `CallbackContext` here:
struct CallbackContext<'a> { ... };
OR type CallbackContext<'a> = &'a CallbackContextImpl;