use hashbrown::HashSet;
use reqwest::header::HeaderMap;
use reqwest::StatusCode;
use crate::CaseInsensitiveString;
use crate::Client;
pub trait PageData {
fn url(&self) -> &str;
fn url_final(&self) -> &str;
fn bytes(&self) -> Option<&[u8]>;
fn html(&self) -> String;
fn html_bytes_u8(&self) -> &[u8];
fn status_code(&self) -> StatusCode;
fn headers(&self) -> Option<&HeaderMap>;
fn is_empty(&self) -> bool;
}
#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
pub trait PageTimingExt: PageData {
fn duration_elapsed(&self) -> tokio::time::Duration;
}
#[cfg(feature = "chrome")]
#[cfg_attr(docsrs, doc(cfg(feature = "chrome")))]
pub trait PageChromeExt: PageData {
fn chrome_page(&self) -> Option<&chromiumoxide::Page>;
fn screenshot_bytes(&self) -> Option<&[u8]>;
}
pub trait Crawler {
type Page: PageData;
fn url(&self) -> &str;
fn status(&self) -> &crate::website::CrawlStatus;
fn links(&self) -> HashSet<CaseInsensitiveString>;
fn pages(&self) -> Option<&[Self::Page]>;
fn client(&self) -> &Option<Client>;
fn crawl(&mut self) -> impl std::future::Future<Output = ()> + Send;
fn crawl_raw(&mut self) -> impl std::future::Future<Output = ()> + Send;
}
#[cfg(feature = "sync")]
#[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
pub trait CrawlerSubscription: Crawler {
fn subscribe(&mut self, capacity: usize) -> tokio::sync::broadcast::Receiver<Self::Page>;
}