use super::types::{CaptureError, Emittable};
use crate::closure::PartitionCargo;
use crate::expansion::Expansion;
use crate::kind::Kind;
use crate::token::CaptureBound;
use core::fmt;
impl CaptureError {
#[must_use]
pub const fn slot(&self) -> u8 {
match self {
Self::Unbounded { .. } => 0,
Self::Unread { .. } => 1,
}
}
}
impl From<CaptureBound> for CaptureError {
fn from(bound: CaptureBound) -> Self {
Self::Unbounded { bound }
}
}
impl fmt::Display for CaptureError {
fn fmt(&self, into: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Unbounded { bound } => write!(into, "{bound}"),
Self::Unread { cause, .. } => write!(into, "{cause}"),
}
}
}
impl core::error::Error for CaptureError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Unbounded { bound } => Some(bound),
Self::Unread { cause, .. } => Some(cause),
}
}
}
impl<K: Kind> Emittable for Expansion<K> {
fn cargos(&self) -> impl Iterator<Item = &PartitionCargo> {
core::iter::once(self.emit())
}
}