summaryrefslogtreecommitdiffstats
path: root/src/tuice/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tuice/state.rs')
-rw-r--r--src/tuice/state.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/tuice/state.rs b/src/tuice/state.rs
new file mode 100644
index 00000000..144c129f
--- /dev/null
+++ b/src/tuice/state.rs
@@ -0,0 +1,25 @@
+//! State code is heavily inspired by crochet's work - see
+//! [here](https://github.com/raphlinus/crochet/blob/master/src/state.rs) for the original.
+
+use std::any::Any;
+
+/// A trait that any sort of [`Component`](crate::tuice::Component) state should implement.
+pub trait State {
+ fn as_any(&self) -> &dyn Any;
+
+ fn are_equal(&self, other: &dyn State) -> bool;
+}
+
+impl<S: PartialEq + 'static> State for S {
+ fn as_any(&self) -> &dyn Any {
+ self
+ }
+
+ fn are_equal(&self, other: &dyn State) -> bool {
+ other
+ .as_any()
+ .downcast_ref()
+ .map(|other| self == other)
+ .unwrap_or(false)
+ }
+}