Trait runa_core::objects::Object

source ·
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§

source

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.

source

type Error: ProtocolError

Error returned by the dispatch method.

source

type Fut<'a>: Future<Output = (Result<(), Self::Error>, usize, usize)> + 'a where Ctx: 'a

The future type returned by the dispatch method.

Required Methods§

source

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§

source

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.

Implementors§

source§

impl<Ctx> Object<Ctx> for Displaywhere Ctx: Client + Debug, Ctx::Object: From<Self>,

§

type Request<'a> where Ctx: 'a = Request

§

type Error = Error

§

type Fut<'a> where Ctx: 'a = impl Future<Output = (Result<(), <Display as Object<Ctx>>::Error>, usize, usize)> + 'a

source§

impl<Ctx> Object<Ctx> for Registrywhere Ctx: Client + Debug,

§

type Request<'a> where Ctx: 'a = Request<'a>

§

type Error = Error

§

type Fut<'a> where Ctx: 'a = impl Future<Output = (Result<(), <Registry as Object<Ctx>>::Error>, usize, usize)> + 'a

source§

impl<Ctx: Client> Object<Ctx> for Callback

§

type Error = Error

§

type Request<'a> where Ctx: 'a = Infallible

§

type Fut<'a> where Ctx: 'a = impl Future<Output = (Result<(), <Callback as Object<Ctx>>::Error>, usize, usize)> + 'a