[][src]Attribute Macro wlroots_dehandle::wlroots_dehandle

#[wlroots_dehandle]

Attribute to automatically call the run method on handles with the remaining block of code.

The syntax in the code to denote a handle being accessed is #[dehandle] let $upgraded_handle = $handle.

Panics

If the handle is invalid (e.g. default constructed, borrowed multiple times, or it is a dangling handle) then your code will panic!.

If this is undesirable, please append ? to the end like so: #[dehandle] let $upgraded_handle = $handle?. This will make it behave as you expect (i.e. the Err is returned early and the return type of the function should be HandleResult<T>)

Example

This example is not tested
impl InputManagerHandler for InputManager {
    #[wlroots_dehandle]
    fn keyboard_added(&mut self,
                      compositor_handle: CompositorHandle,
                      keyboard: KeyboardHandle)
                      -> Option<Box<Keyboard Handler>> {
        {
            #[dehandle] let compositor = compositor_handle;
            #[dehandle] let keyboard = keyboard;
            let server: &mut ::Server = compositor.into();
            server.keyboards.push(keyboard.weak_reference());
            // Now that we have at least one keyboard, update the seat capabilities.
            #[dehandle] let seat = &server.seat.seat;
            let mut capabilities = seat.capabilities();
            capabilities.insert(Capability::Keyboard);
            seat.set_capabilities(capabilities);
            seat.set_keyboard(keyboard.input_device());
        }
        // Due to some weird closure inference rules, this has to be outside
        // of the above block.
        Some(Box::new(::Keyboard))
    }
}