sketchbook 0.0.2

Interactive visual applications in Rust
Documentation
//! Minimal environment for use in examples and tests.
//!
//! This environment implements no aspects.

use crate::env;

/// Minimal events.
///
/// It's not possible to create a value of this type.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum Events {}

/// Minimal page.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
pub struct Page;

/// Minimal mill.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
pub struct Mill;

/// Minimal environment.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
pub struct Env;

impl env::Environment for Env {
    type Mill = Mill;

    type Return = ();

    #[inline]
    fn run<F, E>(self, mut func: F)
    where
        F: FnMut(&mut Self::Mill) -> Result<env::Status, E>,
    {
        while let env::Status::Continue = match func(&mut Mill) {
            Ok(status) => status,
            Err(_) => panic!("Ream returned error."),
        } {
            core::hint::spin_loop();
        }
    }
}

impl env::Mill for Mill {
    type Page = Page;

    #[inline]
    fn new_page(&mut self) -> Self::Page {
        Page::default()
    }
}

impl env::Page for Page {
    type Event = Events;

    #[inline]
    fn start_group(&mut self) {}

    #[inline]
    fn end_group(&mut self) {}

    #[inline]
    fn next_event_in_group(&mut self) -> Option<Self::Event> {
        None
    }

    #[inline]
    fn before_event(&mut self, _event: &Self::Event) {}

    #[inline]
    fn finish_event(&mut self, _event: Self::Event) {}

    #[inline]
    fn status(&self) -> env::Status {
        env::Status::Stop
    }
}