Hi I want to implement a struct only if RetryItem implements Retry trait.
How can i do it?
use reqwest::Client;
use futures::Future;
use std::hash::Hash;
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use std::collections::HashMap;
struct RetryItem<T, Z> {
session: Client,
key: Z,
data: T,
}
struct RetrySystem<T, Z, Y>
where
Z: Future<Output = (RetryItem<T, Y>, Result<(), Box<dyn std::error::Error>>)>,
Y: Eq + Hash,
T: Retry<T, Y>,
{
queue: Vec<T>,
stream: FuturesUnordered<Z>,
concurency: u64,
retry_count: HashMap<Y, u64>,
max_retries: u64,
}
trait Retry<T, Y>
where
Y: Eq + Hash,
{
async fn process(item: RetryItem<T, Y>) -> (RetryItem<T, Y>, Result<(), Box<dyn std::error::Error>>);
}
impl<T, Z, Y> RetrySystem<T, Z, Y>
where
Y: Eq + Hash,
T: Retry<T, Y>,
Z: Future<Output = (RetryItem<T, Y>, Result<(), Box<dyn std::error::Error>>)>,
{
async fn next(&mut self) {
while let Some((item, result)) = self.stream.next().await {
if let Ok(result) = result {
// To do
} else {
let entry = self.retry_count.entry(item.key);
let entry_value = entry.or_insert(0);
if *entry_value <= self.max_retries {
self.stream.push(Retry::<T, Y>::process(item));
}
}
}
}
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
--> src/lib.rs:49:38
|
31 | async fn process(item: RetryItem<T, Y>) -> (RetryItem<T, Y>, Result<(), Box<dyn std::error::Error>>);
| ----------------------------------------------------------------------------------------------------- `Retry::process` defined here
...
49 | self.stream.push(Retry::<T, Y>::process(item));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
For more information about this error, try `rustc --explain E0790`.
error: could not compile `playground` (lib) due to 1 previous error