medina 0.0.2-alpha.5

An asynchronous web crawling engine
Documentation
use std::cmp::Ordering;
use std::collections::BinaryHeap;
use std::time::SystemTime;

#[derive(Clone, Eq, PartialEq)]
pub struct CrawlerScheduler {
    pub host: String,
    pub next_crawl_time: SystemTime,
}

impl Ord for CrawlerScheduler {
    fn cmp(&self, other: &CrawlerScheduler) -> Ordering {
        other
            .next_crawl_time
            .cmp(&self.next_crawl_time)
            .then_with(|| other.host.cmp(&self.host))
    }
}

impl PartialOrd for CrawlerScheduler {
    fn partial_cmp(&self, other: &CrawlerScheduler) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

pub type HostPriorityQueue = BinaryHeap<CrawlerScheduler>;