use std::sync::Arc;
use mssf_core::client::svc_mgmt_client::ResolvedServicePartition;
use super::resolver::BoxError;
pub type TargetSelector =
Arc<dyn Fn(&ResolvedServicePartition) -> Result<DialTarget, SelectError> + Send + Sync>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DialTarget {
pub host: String,
pub port: u16,
}
#[derive(Debug)]
pub enum SelectError {
NoMatch,
Fatal(BoxError),
}
impl std::fmt::Display for SelectError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SelectError::NoMatch => write!(f, "no matching endpoint"),
SelectError::Fatal(e) => write!(f, "{e}"),
}
}
}
impl std::error::Error for SelectError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
SelectError::NoMatch => None,
SelectError::Fatal(e) => Some(&**e),
}
}
}