Skip to main content

Backend

Trait Backend 

Source
pub trait Backend:
    Output
    + Input
    + Cursor { }
Expand description

A rendering backend that presents grid content to a display and provides input events.

This is a pure ergonomic bundle over Output, Input, and Cursor, with no members of its own: every type implementing all three gets Backend for free, and every generic call site that only needs one or two facets should bound on those directly instead of requiring all three through this trait.

§Examples

There is nothing to implement directly: a type gets Backend for free the moment it implements all three facet traits.

use core::time::Duration;
use retroglyph_core::backend::{Backend, Cursor, DrawCell, Input, Output};
use retroglyph_core::event::Event;
use retroglyph_core::grid::Size;

struct NullBackend;

impl Output for NullBackend {
    type Error = core::convert::Infallible;

    fn draw_layers<'a, I>(&mut self, _content: I) -> Result<(), Self::Error>
    where
        I: Iterator<Item = DrawCell<'a>>,
    {
        Ok(())
    }

    fn flush(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }

    fn size(&self) -> Size {
        Size::new(1, 1)
    }

    fn clear(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }
}

impl Input for NullBackend {
    fn poll_event(&mut self, _timeout: Duration) -> Option<Event> {
        None
    }
}

impl Cursor for NullBackend {}

fn assert_is_backend<B: Backend>(_backend: &B) {}
assert_is_backend(&NullBackend);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Output + Input + Cursor> Backend for T