Created input types.
This commit is contained in:
19
src/cell.rs
Normal file
19
src/cell.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use core::cell::Cell;
|
||||
|
||||
/// Provides a view only reference to a [Cell].
|
||||
/// Useful alternative to `&Cell` when an API wants to control where a [Cell]s value can be set.
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct CellView<'a, T: Copy>(&'a Cell<T>);
|
||||
|
||||
impl<T: Copy> CellView<'_, T> {
|
||||
#[inline]
|
||||
pub fn get(self) -> T {
|
||||
self.0.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Copy> From<&'a Cell<T>> for CellView<'a, T> {
|
||||
fn from(value: &'a Cell<T>) -> Self {
|
||||
CellView(value)
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#![no_std]
|
||||
|
||||
pub mod transducer;
|
||||
pub mod transducer;
|
||||
pub mod cell;
|
||||
|
@ -0,0 +1,20 @@
|
||||
use crate::cell::CellView;
|
||||
use crate::transducer::Stateful;
|
||||
|
||||
pub struct StatefulInput<'a, T: Copy> {
|
||||
pub state_cell: CellView<'a, T>,
|
||||
}
|
||||
|
||||
impl<'a, T: Copy> Stateful for StatefulInput<'a, T> {
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn state_cell(&self) -> CellView<'a, Self::Value> {
|
||||
self.state_cell
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn state(&self) -> Self::Value {
|
||||
self.state_cell.get()
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use crate::cell::CellView;
|
||||
|
||||
pub mod input;
|
||||
pub mod output;
|
||||
|
||||
@ -6,5 +8,7 @@ pub mod output;
|
||||
pub trait Stateful {
|
||||
type Value: Copy;
|
||||
|
||||
fn state_cell(&self) -> CellView<Self::Value>;
|
||||
|
||||
fn state(&self) -> Self::Value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user