use ::http::Uri;
use crate::crawler::Tag;
use crate::frontier::seed::Seed;
#[derive(Debug, Clone)]
pub struct Link {
pub(crate) target: Target,
pub(crate) tag: Option<Tag>,
pub(crate) priority: Option<i32>,
}
#[derive(Debug, Clone)]
pub(crate) enum Target {
Href(String),
Seed(Box<Seed>),
}
impl Link {
#[must_use]
pub fn new(href: impl Into<String>) -> Self {
Self {
target: Target::Href(href.into()),
tag: None,
priority: None,
}
}
#[must_use]
pub fn with_tag(mut self, tag: impl Into<Tag>) -> Self {
self.tag = Some(tag.into());
self
}
#[must_use]
pub const fn with_priority(mut self, priority: i32) -> Self {
self.priority = Some(priority);
self
}
}
impl From<&str> for Link {
fn from(href: &str) -> Self {
Self::new(href)
}
}
impl From<String> for Link {
fn from(href: String) -> Self {
Self::new(href)
}
}
impl From<&String> for Link {
fn from(href: &String) -> Self {
Self::new(href.as_str())
}
}
impl From<Uri> for Link {
fn from(uri: Uri) -> Self {
Self::new(uri.to_string())
}
}
impl From<Seed> for Link {
fn from(seed: Seed) -> Self {
Self {
target: Target::Seed(Box::new(seed)),
tag: None,
priority: None,
}
}
}