Struct wayland_server::Resource
source · [−]pub struct Resource<I: Interface> { /* private fields */ }
Expand description
An handle to a wayland resource
This represents a wayland object instantiated in a client session. Several handles to the same object can exist at a given time, and cloning them won’t create a new protocol object, only clone the handle. The lifetime of the protocol object is not tied to the lifetime of these handles, but rather to sending or receiving destroying messages.
These handles are notably used to send events to the associated client,
via the send
method, although you’re encouraged to use methods on the
corresponding Rust objects instead. To convert a Resource<I>
into the
I
Rust object, use the .into()
method.
Implementations
sourceimpl<I> Resource<I> where
I: Interface + From<Resource<I>> + AsRef<Resource<I>>,
impl<I> Resource<I> where
I: Interface + From<Resource<I>> + AsRef<Resource<I>>,
sourcepub fn send(&self, msg: I::Event)
pub fn send(&self, msg: I::Event)
Send an event through this object
The event will be send to the client associated to this object.
sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Check if the object associated with this resource is still alive
Will return false
if the object has been destroyed.
WHen using the use_system_lib
feature, if this object was created
from a raw pointer the crate cannot track its lifetime, and this
method will always return true
. You are responsible for only using
it while it is still alive.
sourcepub fn version(&self) -> u32
pub fn version(&self) -> u32
Retrieve the interface version of this wayland object instance
Returns 0 on dead objects
sourcepub fn equals(&self, other: &Resource<I>) -> bool
pub fn equals(&self, other: &Resource<I>) -> bool
Check if the other resource refers to the same underlying wayland object
You can also use the PartialEq
trait.
sourcepub fn same_client_as<II: Interface>(&self, other: &Resource<II>) -> bool
pub fn same_client_as<II: Interface>(&self, other: &Resource<II>) -> bool
Check if this resource and the other belong to the same client
Always return false if either of them is dead
sourcepub fn post_error(&self, error_code: u32, msg: String)
pub fn post_error(&self, error_code: u32, msg: String)
Posts a protocol error to this resource
The error code can be obtained from the various Error
enums of the protocols.
An error is fatal to the client that caused it.
sourcepub fn user_data(&self) -> &UserData
pub fn user_data(&self) -> &UserData
Access the UserData associated to this object
Each wayland object has an associated UserData, that can store a payload of arbitrary type and is shared by all proxies of this object.
See UserData documentation for more details.
sourceimpl<I> Resource<I> where
I: Interface + From<Resource<I>> + AsRef<Resource<I>>,
impl<I> Resource<I> where
I: Interface + From<Resource<I>> + AsRef<Resource<I>>,
sourcepub fn is_external(&self) -> bool
pub fn is_external(&self) -> bool
Check whether this resource is managed by the library or not
See from_c_ptr
for details.
NOTE: This method will panic if called while the use_system_lib
feature is not
activated
sourcepub fn c_ptr(&self) -> *mut wl_resource
pub fn c_ptr(&self) -> *mut wl_resource
Get a raw pointer to the underlying wayland object
Retrieve a pointer to the object from the libwayland-server.so
library.
You will mostly need it to interface with C libraries needing access
to wayland objects (to initialize an opengl context for example).
NOTE: This method will panic if called while the use_system_lib
feature is not
activated
sourcepub unsafe fn from_c_ptr(_ptr: *mut wl_resource) -> Self where
I: From<Resource<I>>,
pub unsafe fn from_c_ptr(_ptr: *mut wl_resource) -> Self where
I: From<Resource<I>>,
Create a Resource
instance from a C pointer
Create a Resource
from a raw pointer to a wayland object from the
C library.
If the pointer was previously obtained by the c_ptr()
method, this
constructs a new resource handle for the same object just like the
clone()
method would have.
If the object was created by some other C library you are interfacing
with, it will be created in an “unmanaged” state: wayland-server will
treat it as foreign, and as such most of the safeties will be absent.
Notably the lifetime of the object can’t be tracked, so the alive()
method will always return false
and you are responsible of not using
an object past its destruction (as this would cause a protocol error).
You will also be unable to associate any user data pointer to this object.
In order to handle protocol races, invoking it with a NULL pointer will create an already-dead object.
NOTE: This method will panic if called while the use_system_lib
feature is not
activated
Safety
The provided pointer must be a valid pointer to a wayland object from
libwayland-client
associated to the correct interface.
Trait Implementations
sourceimpl AsRef<Resource<AnonymousObject>> for AnonymousObject
impl AsRef<Resource<AnonymousObject>> for AnonymousObject
sourceimpl AsRef<Resource<WlCallback>> for WlCallback
impl AsRef<Resource<WlCallback>> for WlCallback
sourceimpl AsRef<Resource<WlCompositor>> for WlCompositor
impl AsRef<Resource<WlCompositor>> for WlCompositor
sourceimpl AsRef<Resource<WlDataDevice>> for WlDataDevice
impl AsRef<Resource<WlDataDevice>> for WlDataDevice
sourceimpl AsRef<Resource<WlDataOffer>> for WlDataOffer
impl AsRef<Resource<WlDataOffer>> for WlDataOffer
sourceimpl AsRef<Resource<WlDataSource>> for WlDataSource
impl AsRef<Resource<WlDataSource>> for WlDataSource
sourceimpl AsRef<Resource<WlKeyboard>> for WlKeyboard
impl AsRef<Resource<WlKeyboard>> for WlKeyboard
sourceimpl AsRef<Resource<WlShellSurface>> for WlShellSurface
impl AsRef<Resource<WlShellSurface>> for WlShellSurface
sourceimpl AsRef<Resource<WlSubcompositor>> for WlSubcompositor
impl AsRef<Resource<WlSubcompositor>> for WlSubcompositor
sourceimpl AsRef<Resource<WlSubsurface>> for WlSubsurface
impl AsRef<Resource<WlSubsurface>> for WlSubsurface
sourceimpl From<AnonymousObject> for Resource<AnonymousObject>
impl From<AnonymousObject> for Resource<AnonymousObject>
sourcefn from(value: AnonymousObject) -> Self
fn from(value: AnonymousObject) -> Self
Converts to this type from the input type.
sourceimpl From<Resource<AnonymousObject>> for AnonymousObject
impl From<Resource<AnonymousObject>> for AnonymousObject
sourceimpl From<Resource<WlCallback>> for WlCallback
impl From<Resource<WlCallback>> for WlCallback
sourceimpl From<Resource<WlCompositor>> for WlCompositor
impl From<Resource<WlCompositor>> for WlCompositor
sourceimpl From<Resource<WlDataDevice>> for WlDataDevice
impl From<Resource<WlDataDevice>> for WlDataDevice
sourceimpl From<Resource<WlDataDeviceManager>> for WlDataDeviceManager
impl From<Resource<WlDataDeviceManager>> for WlDataDeviceManager
sourceimpl From<Resource<WlDataOffer>> for WlDataOffer
impl From<Resource<WlDataOffer>> for WlDataOffer
sourceimpl From<Resource<WlDataSource>> for WlDataSource
impl From<Resource<WlDataSource>> for WlDataSource
sourceimpl From<Resource<WlKeyboard>> for WlKeyboard
impl From<Resource<WlKeyboard>> for WlKeyboard
sourceimpl From<Resource<WlShellSurface>> for WlShellSurface
impl From<Resource<WlShellSurface>> for WlShellSurface
sourceimpl From<Resource<WlSubcompositor>> for WlSubcompositor
impl From<Resource<WlSubcompositor>> for WlSubcompositor
sourceimpl From<Resource<WlSubsurface>> for WlSubsurface
impl From<Resource<WlSubsurface>> for WlSubsurface
sourceimpl From<WlCallback> for Resource<WlCallback>
impl From<WlCallback> for Resource<WlCallback>
sourcefn from(value: WlCallback) -> Self
fn from(value: WlCallback) -> Self
Converts to this type from the input type.
sourceimpl From<WlCompositor> for Resource<WlCompositor>
impl From<WlCompositor> for Resource<WlCompositor>
sourcefn from(value: WlCompositor) -> Self
fn from(value: WlCompositor) -> Self
Converts to this type from the input type.
sourceimpl From<WlDataDevice> for Resource<WlDataDevice>
impl From<WlDataDevice> for Resource<WlDataDevice>
sourcefn from(value: WlDataDevice) -> Self
fn from(value: WlDataDevice) -> Self
Converts to this type from the input type.
sourceimpl From<WlDataDeviceManager> for Resource<WlDataDeviceManager>
impl From<WlDataDeviceManager> for Resource<WlDataDeviceManager>
sourcefn from(value: WlDataDeviceManager) -> Self
fn from(value: WlDataDeviceManager) -> Self
Converts to this type from the input type.
sourceimpl From<WlDataOffer> for Resource<WlDataOffer>
impl From<WlDataOffer> for Resource<WlDataOffer>
sourcefn from(value: WlDataOffer) -> Self
fn from(value: WlDataOffer) -> Self
Converts to this type from the input type.
sourceimpl From<WlDataSource> for Resource<WlDataSource>
impl From<WlDataSource> for Resource<WlDataSource>
sourcefn from(value: WlDataSource) -> Self
fn from(value: WlDataSource) -> Self
Converts to this type from the input type.
sourceimpl From<WlKeyboard> for Resource<WlKeyboard>
impl From<WlKeyboard> for Resource<WlKeyboard>
sourcefn from(value: WlKeyboard) -> Self
fn from(value: WlKeyboard) -> Self
Converts to this type from the input type.
sourceimpl From<WlShellSurface> for Resource<WlShellSurface>
impl From<WlShellSurface> for Resource<WlShellSurface>
sourcefn from(value: WlShellSurface) -> Self
fn from(value: WlShellSurface) -> Self
Converts to this type from the input type.
sourceimpl From<WlSubcompositor> for Resource<WlSubcompositor>
impl From<WlSubcompositor> for Resource<WlSubcompositor>
sourcefn from(value: WlSubcompositor) -> Self
fn from(value: WlSubcompositor) -> Self
Converts to this type from the input type.
sourceimpl From<WlSubsurface> for Resource<WlSubsurface>
impl From<WlSubsurface> for Resource<WlSubsurface>
sourcefn from(value: WlSubsurface) -> Self
fn from(value: WlSubsurface) -> Self
Converts to this type from the input type.
sourceimpl<I: Interface + From<Resource<I>> + AsRef<Resource<I>>> PartialEq<Resource<I>> for Resource<I>
impl<I: Interface + From<Resource<I>> + AsRef<Resource<I>>> PartialEq<Resource<I>> for Resource<I>
impl<I: Interface + From<Resource<I>> + AsRef<Resource<I>>> Eq for Resource<I>
Auto Trait Implementations
impl<I> !RefUnwindSafe for Resource<I>
impl<I> Send for Resource<I> where
I: Sync,
impl<I> Sync for Resource<I> where
I: Sync,
impl<I> Unpin for Resource<I>
impl<I> !UnwindSafe for Resource<I>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more