Trait input::Userdata
[−]
[src]
pub trait Userdata { unsafe fn userdata<T: 'static>(&self) -> Option<&T> { ... } unsafe fn userdata_mut<T: 'static>(&mut self) -> Option<&mut T> { ... } unsafe fn set_userdata<T: 'static, U: 'static>(
&mut self,
new: Option<T>
) -> Option<U> { ... } }
Trait to deal with userdata attached to this struct.
Provided Methods
unsafe fn userdata<T: 'static>(&self) -> Option<&T>
Receive a reference to the attached userdata, if one exists.
Unsafety
Receiving userdata is unsafe as multiple references to the same underlying libinput struct
may exist. As such any reference may become invalid if changed using set_userdata
.
unsafe fn userdata_mut<T: 'static>(&mut self) -> Option<&mut T>
Receive a mutable reference to the attached userdata, if one exists.
Unsafety
Receiving userdata is unsafe as multiple references to the same underlying libinput struct
may exist. As such any reference may become invalid if changed using set_userdata
.
Additionally multiple mutable references may be created through the existance of multiple
structs using the same libinput reference. If you have control over the userdata make sure
to store Mutex
to be on the safe side.
unsafe fn set_userdata<T: 'static, U: 'static>(
&mut self,
new: Option<T>
) -> Option<U>
&mut self,
new: Option<T>
) -> Option<U>
Set userdata and receive the currently set userdata
Sets new userdata or nothing in place of any existing one and returns the currently set userdata if one exists.
Unsafety
Multiple references to the same underlying libinput struct may exist. As such this function allows for shared mutable access, which is unsafe. Also this means this function might invalidate references to the currently set userdata, once dropped.
Use a Mutex
when storing new userdata to mitiage some of these problems.
Note
Stored userdata is dropped correctly, if the last reference is hold by rust and goes out of scope normally.
Implementors
impl Userdata for Libinput
impl Userdata for DeviceGroup
impl Userdata for Device
impl Userdata for TabletTool
impl Userdata for TabletPadModeGroup
impl Userdata for Seat