use std::fmt;
use uuid::Uuid;
use crate::source::SourceKind;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct HostId {
uuid: Uuid,
source: SourceKind,
in_container: bool,
}
impl HostId {
pub(crate) fn new(uuid: Uuid, source: SourceKind, in_container: bool) -> Self {
Self {
uuid,
source,
in_container,
}
}
#[must_use]
pub fn as_uuid(&self) -> Uuid {
self.uuid
}
#[must_use]
pub fn source(&self) -> SourceKind {
self.source
}
#[must_use]
pub fn in_container(&self) -> bool {
self.in_container
}
#[must_use]
pub fn summary(&self) -> HostIdSummary<'_> {
HostIdSummary(self)
}
}
#[derive(Debug)]
pub struct HostIdSummary<'a>(&'a HostId);
impl fmt::Display for HostIdSummary<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.0.source, self.0.uuid)
}
}
impl fmt::Display for HostId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.uuid.fmt(f)
}
}
#[derive(Debug)]
pub enum ResolveOutcome {
Found(HostId),
Skipped(SourceKind),
Errored(SourceKind, crate::Error),
}
impl ResolveOutcome {
#[must_use]
pub fn source(&self) -> SourceKind {
match self {
Self::Found(id) => id.source(),
Self::Skipped(kind) | Self::Errored(kind, _) => *kind,
}
}
#[must_use]
pub fn host_id(&self) -> Option<&HostId> {
match self {
Self::Found(id) => Some(id),
Self::Skipped(_) | Self::Errored(_, _) => None,
}
}
}