use crate::convert;
use crate::error::Result;
use crate::reset_time::ResetTimeKind;
use time::Duration;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Vendor {
PolliDraft,
Akamai,
Github,
Gitlab,
Linear,
OpenAI,
Reddit,
Twilio,
Twitter,
Vimeo,
}
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct RateLimitVariant {
pub(crate) vendor: Vendor,
pub(crate) duration: Option<Duration>,
pub(crate) limit_header: Option<String>,
pub(crate) used_header: Option<String>,
pub(crate) remaining_header: String,
pub(crate) reset_header: String,
pub(crate) reset_kind: ResetTimeKind,
}
impl RateLimitVariant {
#[must_use]
pub(crate) const fn new(
vendor: Vendor,
duration: Option<Duration>,
limit_header: Option<String>,
used_header: Option<String>,
remaining_header: String,
reset_header: String,
reset_kind: ResetTimeKind,
) -> Self {
Self {
vendor,
duration,
limit_header,
used_header,
remaining_header,
reset_header,
reset_kind,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct Limit {
pub(crate) count: usize,
}
impl Limit {
pub(crate) fn new<T: AsRef<str>>(value: T) -> Result<Self> {
Ok(Self {
count: convert::to_usize(value.as_ref())?,
})
}
}
impl From<usize> for Limit {
fn from(count: usize) -> Self {
Self { count }
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct Used {
pub(crate) count: usize,
}
impl Used {
pub(crate) fn new(value: &str) -> Result<Self> {
Ok(Self {
count: convert::to_usize(value)?,
})
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct Remaining {
pub(crate) count: usize,
}
impl Remaining {
pub(crate) fn new(value: &str) -> Result<Self> {
Ok(Self {
count: convert::to_usize(value)?,
})
}
}