pub mod get_blob;
pub mod get_blocks;
pub mod get_checkout;
pub mod get_head;
pub mod get_host_status;
pub mod get_latest_commit;
pub mod get_record;
pub mod get_repo;
pub mod get_repo_status;
pub mod list_blobs;
pub mod list_hosts;
pub mod list_repos;
pub mod list_repos_by_collection;
pub mod notify_of_update;
pub mod request_crawl;
#[cfg(feature = "streaming")]
pub mod subscribe_repos;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum HostStatus<S: BosStr = DefaultStr> {
Active,
Idle,
Offline,
Throttled,
Banned,
Other(S),
}
impl<S: BosStr> HostStatus<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Active => "active",
Self::Idle => "idle",
Self::Offline => "offline",
Self::Throttled => "throttled",
Self::Banned => "banned",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"active" => Self::Active,
"idle" => Self::Idle,
"offline" => Self::Offline,
"throttled" => Self::Throttled,
"banned" => Self::Banned,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> AsRef<str> for HostStatus<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> core::fmt::Display for HostStatus<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> serde::Serialize for HostStatus<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: serde::Deserialize<'de> + BosStr> serde::Deserialize<'de> for HostStatus<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr> jacquard_common::IntoStatic for HostStatus<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = HostStatus<S::Output>;
fn into_static(self) -> Self::Output {
match self {
HostStatus::Active => HostStatus::Active,
HostStatus::Idle => HostStatus::Idle,
HostStatus::Offline => HostStatus::Offline,
HostStatus::Throttled => HostStatus::Throttled,
HostStatus::Banned => HostStatus::Banned,
HostStatus::Other(v) => HostStatus::Other(v.into_static()),
}
}
}