rustup_available_packages/
source.rs1use chrono::NaiveDate;
2use std::borrow::Cow;
3
4pub trait SourceInfo {
6 type Url: AsRef<str>;
8
9 fn make_manifest_url(&self, _: NaiveDate) -> Self::Url;
11
12 fn make_latest_manifest_url(&self) -> Self::Url;
14}
15
16pub struct DefaultSource<'a> {
18 channel: &'a str,
19 base_url: Cow<'a, str>,
20}
21
22impl<'a> DefaultSource<'a> {
23 pub const DEFAULT_BASE_URL: &'static str = "https://static.rust-lang.org/dist";
25
26 pub fn new(channel: &'a str) -> Self {
28 DefaultSource {
29 channel,
30 base_url: Cow::Borrowed(Self::DEFAULT_BASE_URL),
31 }
32 }
33
34 pub fn override_base(&mut self, base_url: Cow<'a, str>) {
36 self.base_url = base_url
37 }
38}
39
40impl<'a> SourceInfo for DefaultSource<'a> {
41 type Url = String;
42
43 fn make_manifest_url(&self, date: NaiveDate) -> Self::Url {
44 format!(
45 "{}/{}/channel-rust-{}.toml",
46 self.base_url, date, self.channel
47 )
48 }
49
50 fn make_latest_manifest_url(&self) -> Self::Url {
51 format!("{}/channel-rust-{}.toml", self.base_url, self.channel)
52 }
53}