use core::fmt;
use std::borrow::Cow;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct BackendId(String);
impl BackendId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for BackendId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum BackendFamily {
Algorithmic,
ReferenceData,
CompressedData,
Composite,
Other(String),
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum BackendFamilyPosture {
Algorithmic,
DataBacked,
Routing,
Other,
}
impl BackendFamilyPosture {
pub const fn label(self) -> &'static str {
match self {
Self::Algorithmic => "algorithmic",
Self::DataBacked => "data-backed",
Self::Routing => "routing",
Self::Other => "other",
}
}
}
impl fmt::Display for BackendFamilyPosture {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label())
}
}
impl BackendFamily {
pub fn display_name(&self) -> Cow<'_, str> {
match self {
Self::Algorithmic => Cow::Borrowed("Algorithmic"),
Self::ReferenceData => Cow::Borrowed("ReferenceData"),
Self::CompressedData => Cow::Borrowed("CompressedData"),
Self::Composite => Cow::Borrowed("Composite"),
Self::Other(value) => Cow::Owned(format!("Other({value})")),
}
}
pub const fn is_data_backed(&self) -> bool {
matches!(self, Self::ReferenceData | Self::CompressedData)
}
pub const fn is_algorithmic(&self) -> bool {
matches!(self, Self::Algorithmic)
}
pub const fn is_routing(&self) -> bool {
matches!(self, Self::Composite)
}
pub const fn posture(&self) -> BackendFamilyPosture {
if self.is_algorithmic() {
BackendFamilyPosture::Algorithmic
} else if self.is_data_backed() {
BackendFamilyPosture::DataBacked
} else if self.is_routing() {
BackendFamilyPosture::Routing
} else {
BackendFamilyPosture::Other
}
}
pub const fn posture_label(&self) -> &'static str {
self.posture().label()
}
}
impl fmt::Display for BackendFamily {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.display_name())
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum AccuracyClass {
Exact,
High,
Moderate,
Approximate,
Unknown,
}
impl AccuracyClass {
pub const fn label(self) -> &'static str {
match self {
Self::Exact => "Exact",
Self::High => "High",
Self::Moderate => "Moderate",
Self::Approximate => "Approximate",
Self::Unknown => "Unknown",
}
}
}
impl fmt::Display for AccuracyClass {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label())
}
}
#[cfg(test)]
#[path = "identity_tests.rs"]
mod tests;