Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_core/src/bot.rs

1017 bytes, 5 runs

created by r1870400018:64, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! Provides a simple foundation for code delegated to child threads. A `Bot` is intended to be
2//! the main loop function for a child thread, `BaseMsg` and the `CtrlMsg` trait provide some
3//! baseline message types that can be elaborated in your application via composition (see
4//! `oxedyne_fe2o3_o3db_sync::bot`).
5
6use crate::{
7 prelude::*,
8 error,
9 GenTag,
10};
11
12pub trait CtrlMsg {
13 fn finish() -> Self;
14 fn ready() -> Self;
15}
16
17pub trait ErrorMsg<T: GenTag> where error::Error<T>: std::error::Error {
18 fn error(e: Error<T>) -> Self;
19}
20
21#[derive(Clone, Debug)]
22pub enum BaseMsg<T: GenTag> where error::Error<T>: std::error::Error {
23 Error(Error<T>),
24 Finish,
25 Ready,
26}
27
28impl<T: GenTag> CtrlMsg for BaseMsg<T> where error::Error<T>: std::error::Error {
29 fn finish() -> Self { BaseMsg::Finish }
30 fn ready() -> Self { BaseMsg::Ready }
31}
32
33impl<T: GenTag> ErrorMsg<T> for BaseMsg<T> where error::Error<T>: std::error::Error {
34 fn error(e: Error<T>) -> Self { BaseMsg::Error(e) }
35}