subspace_shell/registry/
configuration.rs1use super::BoardRegistration;
4use std::{any::Any, sync::Arc};
5
6#[derive(Clone)]
7pub struct BoardConfiguration {
8 value: Arc<dyn Any + Send + Sync>,
9 equal: fn(&dyn Any, &dyn Any) -> bool,
10}
11
12impl PartialEq for BoardConfiguration {
13 fn eq(&self, other: &Self) -> bool {
14 (self.equal)(self.value.as_ref(), other.value.as_ref())
15 }
16}
17
18fn equal<T: PartialEq + 'static>(left: &dyn Any, right: &dyn Any) -> bool {
20 match (left.downcast_ref::<T>(), right.downcast_ref::<T>()) {
21 (Some(left), Some(right)) => left == right,
22 _ => false,
23 }
24}
25
26impl BoardRegistration {
27 pub fn with_configuration<T: PartialEq + Send + Sync + 'static>(mut self, value: T) -> Self {
30 self.configuration = Some(BoardConfiguration {
31 value: Arc::new(value),
32 equal: equal::<T>,
33 });
34 self
35 }
36}