use crate::utils::UtcTime;
use chrono::Utc;
use derive_more::Display;
use serde::Deserialize;
use serde::Serialize;
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct AnnotatedUrl {
pub url: String,
pub description: Option<String>,
pub created: Option<UtcTime>,
}
impl AnnotatedUrl {
pub fn new(url: String, description: Option<String>) -> Self {
Self {
url,
description,
created: Some(Utc::now()),
}
}
}
impl Display for AnnotatedUrl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.url)?;
if let Some(d) = &self.description {
write!(f, " ({d})")?;
}
Ok(())
}
}
impl From<&str> for AnnotatedUrl {
fn from(value: &str) -> Self {
AnnotatedUrl {
url: value.into(),
description: None,
created: None,
}
}
}