pub trait Object<Ctx: Client>: 'static {
type Request<'a>: Deserialize<'a>
where Ctx: 'a;
type Error: ProtocolError;
type Fut<'a>: Future<Output = (Result<(), Self::Error>, usize, usize)> + 'a
where Ctx: 'a;
// Required method
fn dispatch<'a>(
ctx: &'a mut Ctx,
object_id: u32,
msg: Self::Request<'a>
) -> Self::Fut<'a>;
// Provided method
fn on_disconnect(
&mut self,
_server_ctx: &mut Ctx::ServerContext,
_state: &mut dyn Any
) { ... }
}
Expand description
A wayland object.
An object can either be a MonoObject
or an AnyObject
.
A MonoObject
would be an object that is known to be of a single type,
and it will have a manually implemented RequestDispatch
trait. Its
Object
trait implementation can be generated from the RequestDispatch
implementation with the help of the #[wayland_object]
macro.
An AnyObject
can be seen as a union of multiple MonoObject
types. Its
Object
trait implementation can be generated using the
#[derive(Object)]
macro.
Required Associated Types§
sourcetype Request<'a>: Deserialize<'a>
where
Ctx: 'a
type Request<'a>: Deserialize<'a> where Ctx: 'a
The type of wayland messages that this object can receive.
This is what the dispatch
method accepts.
sourcetype Error: ProtocolError
type Error: ProtocolError
Error returned by the dispatch
method.
Required Methods§
sourcefn dispatch<'a>(
ctx: &'a mut Ctx,
object_id: u32,
msg: Self::Request<'a>
) -> Self::Fut<'a>
fn dispatch<'a>( ctx: &'a mut Ctx, object_id: u32, msg: Self::Request<'a> ) -> Self::Fut<'a>
Dispatch a wayland request to this object. Returns a future, that resolves to (Result, usize, usize), which are the result of the request, the number of bytes and file descriptors in the request, respectively.
Provided Methods§
sourcefn on_disconnect(
&mut self,
_server_ctx: &mut Ctx::ServerContext,
_state: &mut dyn Any
)
fn on_disconnect( &mut self, _server_ctx: &mut Ctx::ServerContext, _state: &mut dyn Any )
A function that will be called when the client disconnects. It should free up allocated resources if any. This function only gets reference to the server context, because:
- It cannot send anything to the client, as it has already
disconnected. So no
Ctx::Connection
. - The object store will be borrowed mutably when this is called, to
iterate over all objects and calling their on_disconnect. So no
Ctx::ObjectStore
. - Adding more event handlers at this point doesn’t make sense. So no
Ctx::EventDispatcher
.
This function also gets access to the singleton state associated with this object type, if there is any.