struct ServiceA{
field_a: String,
}
struct ServiceB{
field_b: i32,
}
impl ServiceA {
pub async fn init(self: Arc<Self>){
tokio::spawn(async move { self.daemon_task().await});
}
async fn daemon_task(&self){
//do loop task
}
}
enum Service {
A(ServiceA),
B(ServiceB)
}
I have arc_obj: Arc<Service>
. How can I downgrade it to an Arc<ServiceA>
when arc_obj
is Service::A
?
I use enum dispatch and tokio, so I wrap a Service
object in Arc
to use it in multiple threads. ServiceA needs init to start a daemon task, which wants an Arc<ServiceA>
. How can I get it?
New contributor
Song Xu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1