use async_trait::async_trait; use futures_timer::Delay; use medina::{Crawler, Error, Page, PageResult}; pub struct RootPage { pub url: String, } pub struct FakePage { pub url: String, } pub struct FakePageResult {} #[async_trait] impl PageResult for FakePageResult { async fn save_results(&self) -> Result<(), Error> { Delay::new(std::time::Duration::from_millis(50)).await; println!("Saved page result"); Ok(()) } } #[async_trait] impl Page for RootPage { async fn process_request( &self, ) -> Result<(Vec>, Vec>), Error> { let mut vec: Vec> = Vec::with_capacity(50 * 26); for ch in b'a'..(b'z' + 1) { for i in 1..50 + 1 { vec.push(Box::new(FakePage { url: format!("https://{}.com/{}", ch as char, i), })); } } return Ok((vec, Vec::new())); } fn get_url(&self) -> &String { return &self.url; } } #[async_trait] impl Page for FakePage { async fn process_request( &self, ) -> Result<(Vec>, Vec>), Error> { Delay::new(std::time::Duration::from_millis(250)).await; return Ok(( Vec::new(), vec![Box::new(FakePageResult {}), Box::new(FakePageResult {})], )); } fn get_url(&self) -> &String { return &self.url; } } #[tokio::main] async fn main() { Crawler::with_capacity(1_300, 0.0001) .push_item(Box::new(RootPage { url: "https://root.com".to_string(), })) .set_default_request_rate(5.0) .run(50, 30) .await; }