From b5ff7e3347bd1d8ea8346d6ec7e06bed78b1ddad Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 3 Dec 2023 13:37:32 +0100 Subject: [PATCH] Add Instance::from_root_domain(), change documentation wording --- src/instance.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/instance.rs b/src/instance.rs index fc0bcda..6a3b9af 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -70,7 +70,7 @@ impl PartialEq for LimitsInformation { } impl Instance { - /// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle), where `limited` is whether or not to automatically use rate limits. + /// Creates a new [`Instance`] from the [relevant instance urls](UrlBundle), where `limited` is whether Chorus will track and enforce rate limits for this instance. pub async fn new(urls: UrlBundle, limited: bool) -> ChorusResult { let limits_information; if limited { @@ -99,12 +99,22 @@ impl Instance { }; Ok(instance) } + pub(crate) fn clone_limits_if_some(&self) -> Option> { if self.limits_information.is_some() { return Some(self.limits_information.as_ref().unwrap().ratelimits.clone()); } None } + + /// Creates a new [`Instance`] by trying to get the [relevant instance urls](UrlBundle) from a root domain. + /// Shorthand for `Instance::new(UrlBundle::from_root_domain(root_domain).await?)`. + /// + /// If `limited` is `true`, then Chorus will track and enforce rate limits for this instance. + pub async fn from_root_domain(root_domain: &str, limited: bool) -> ChorusResult { + let urls = UrlBundle::from_root_domain(root_domain).await?; + Instance::new(urls, limited).await + } } #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]