use crate::error::AraComError;
use crate::event::EventStream;
#[derive(Debug, Clone)]
pub struct FieldConfig {
pub has_getter: bool,
pub has_setter: bool,
pub has_notifier: bool,
}
impl Default for FieldConfig {
fn default() -> Self {
Self {
has_getter: true,
has_setter: true,
has_notifier: true,
}
}
}
pub trait FieldGetter<T>: Send + Sync {
fn get(&self) -> impl std::future::Future<Output = Result<T, AraComError>> + Send;
}
pub trait FieldSetter<T>: Send + Sync {
fn set(&self, value: T) -> impl std::future::Future<Output = Result<(), AraComError>> + Send;
}
pub trait FieldNotifier<T>: Send + Sync {
fn subscribe(&self) -> EventStream<T>;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_field_config_default() {
let cfg = FieldConfig::default();
assert!(cfg.has_getter);
assert!(cfg.has_setter);
assert!(cfg.has_notifier);
}
#[test]
fn test_field_config_read_only() {
let cfg = FieldConfig {
has_getter: true,
has_setter: false,
has_notifier: false,
};
assert!(cfg.has_getter);
assert!(!cfg.has_setter);
assert!(!cfg.has_notifier);
}
}