Add Instance::from_root_domain(), change documentation wording

This commit is contained in:
bitfl0wer 2023-12-03 13:37:32 +01:00
parent 1a52975dbd
commit b5ff7e3347
1 changed files with 11 additions and 1 deletions

View File

@ -70,7 +70,7 @@ impl PartialEq for LimitsInformation {
} }
impl Instance { 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<Instance> { pub async fn new(urls: UrlBundle, limited: bool) -> ChorusResult<Instance> {
let limits_information; let limits_information;
if limited { if limited {
@ -99,12 +99,22 @@ impl Instance {
}; };
Ok(instance) Ok(instance)
} }
pub(crate) fn clone_limits_if_some(&self) -> Option<HashMap<LimitType, Limit>> { pub(crate) fn clone_limits_if_some(&self) -> Option<HashMap<LimitType, Limit>> {
if self.limits_information.is_some() { if self.limits_information.is_some() {
return Some(self.limits_information.as_ref().unwrap().ratelimits.clone()); return Some(self.limits_information.as_ref().unwrap().ratelimits.clone());
} }
None 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<Instance> {
let urls = UrlBundle::from_root_domain(root_domain).await?;
Instance::new(urls, limited).await
}
} }
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]