pub trait UserCommunication {
async fn send_sms(self: &Self, phone: &str, code: &str);
async fn send_email(self: &Self, email: &str, code: &str);
}
pub struct AuthenticationService {
communicator: Box<dyn UserCommunication>,
}
如上代码,希望communicator是个动态分发的trait,不咋想用async-trait实现
1
共 1 条评论, 1 页
评论区
写评论我今天发的 Rust 日报有介绍 dynify 库
你的示例已经作为了它的一个 example。
其他方式见我总结的 dyn-afit。