use core::fmt::Debug;
use crate::binding::ProviderContextIdentity;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProviderContextPinError {
ContextUnavailable(ProviderContextIdentity),
PinCountOverflow(ProviderContextIdentity),
}
impl core::fmt::Display for ProviderContextPinError {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::ContextUnavailable(identity) => write!(
formatter,
"provider context {identity:?} is no longer accepting work"
),
Self::PinCountOverflow(identity) => write!(
formatter,
"provider context {identity:?} has too many outstanding pins"
),
}
}
}
impl std::error::Error for ProviderContextPinError {}
pub trait ProviderContextPin: Send + Sync + Debug {
fn context(&self) -> ProviderContextIdentity;
}
pub trait ProviderContextPinSource: Send + Sync + Debug {
fn context(&self) -> ProviderContextIdentity;
fn pin(&self) -> Result<Box<dyn ProviderContextPin>, ProviderContextPinError>;
}