use anyhow::{anyhow, Result};
use async_trait::async_trait;
#[async_trait]
pub trait Fetch {
type Error;
async fn fetch(&self) -> Result<(), Self::Error>;
}
pub struct foo;
#[async_trait]
impl Fetch for foo {
type Error = anyhow::Error;
async fn fetch(&self) -> Result<(), Self::Error> {
Err(anyhow!("hahha"))
}
}
pub struct bar;
#[async_trait]
impl Fetch for bar {
type Error = anyhow::Error;
async fn fetch(&self) -> Result<(), Self::Error> {
Err(anyhow!("wowo"))
}
}
async fn todo(t: &dyn Fetch) -> Result<()> {
Ok(t.fetch().await?)
}
#[tokio::main]
async fn main() -> Result<()> {
let foo1 = foo;
let x = todo(&foo1).await?;
Ok(())
}
how to sloved this?