macroonz_compiler/host/
type_contract.rs1use super::types::{CaptureError, Emittable};
4use crate::closure::PartitionCargo;
5use crate::expansion::Expansion;
6use crate::kind::Kind;
7use crate::token::CaptureBound;
8use core::fmt;
9
10impl CaptureError {
11 #[must_use]
15 pub const fn slot(&self) -> u8 {
16 match self {
17 Self::Unbounded { .. } => 0,
18 Self::Unread { .. } => 1,
19 }
20 }
21}
22
23impl From<CaptureBound> for CaptureError {
24 fn from(bound: CaptureBound) -> Self {
25 Self::Unbounded { bound }
26 }
27}
28
29impl fmt::Display for CaptureError {
30 fn fmt(&self, into: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Self::Unbounded { bound } => write!(into, "{bound}"),
33 Self::Unread { cause, .. } => write!(into, "{cause}"),
34 }
35 }
36}
37
38impl core::error::Error for CaptureError {
39 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
40 match self {
41 Self::Unbounded { bound } => Some(bound),
42 Self::Unread { cause, .. } => Some(cause),
43 }
44 }
45}
46
47impl<K: Kind> Emittable for Expansion<K> {
48 fn cargos(&self) -> impl Iterator<Item = &PartitionCargo> {
50 core::iter::once(self.emit())
51 }
52}