作者回复: 嗯,确实如此。非常棒!
作者回复: 对
作者回复: 👍
作者回复: 如果你使用 trait object,那么你的 service 定义就不需要用 Store trait bound 了,可以这样: pub struct Service { inner: Arc<ServiceInner>, broadcaster: Arc<Broadcaster>, } pub struct ServiceInner { store: Box<dyn Store>, on_received: Vec<fn(&CommandRequest)>, on_executed: Vec<fn(&CommandResponse)>, on_before_send: Vec<fn(&mut CommandResponse)>, on_after_send: Vec<fn()>, }
作者回复: 可以看看 Fundamentals of software architecture
作者回复: 👍 第二题可以看 github repo 下这章的代码