use chrono::NaiveDate;
use std::borrow::Cow;
pub trait SourceInfo {
type Url: AsRef<str>;
fn make_manifest_url(&self, _: NaiveDate) -> Self::Url;
fn make_latest_manifest_url(&self) -> Self::Url;
}
pub struct DefaultSource<'a> {
channel: &'a str,
base_url: Cow<'a, str>,
}
impl<'a> DefaultSource<'a> {
pub const DEFAULT_BASE_URL: &'static str = "https://static.rust-lang.org/dist";
pub fn new(channel: &'a str) -> Self {
DefaultSource {
channel,
base_url: Cow::Borrowed(Self::DEFAULT_BASE_URL),
}
}
pub fn override_base(&mut self, base_url: Cow<'a, str>) {
self.base_url = base_url
}
}
impl<'a> SourceInfo for DefaultSource<'a> {
type Url = String;
fn make_manifest_url(&self, date: NaiveDate) -> Self::Url {
format!(
"{}/{}/channel-rust-{}.toml",
self.base_url, date, self.channel
)
}
fn make_latest_manifest_url(&self) -> Self::Url {
format!("{}/channel-rust-{}.toml", self.base_url, self.channel)
}
}