Skip to main content

macroonz_compiler/host/
encode.rs

1//! The canonical bytes one refused capture is named by.
2
3use super::types::CaptureError;
4use crate::identity::encode_bytes;
5use crate::token::encode_token_path;
6
7impl CaptureError {
8    /// This refusal's complete canonical material: which row it is, the stable name of what stopped the read, and — for a refusal about one token — that token's declaration-local path.
9    ///
10    /// The row's position leads, so two rows whose names happened to coincide still derive two related identities.
11    /// The producer-local span handle is excluded: captures of one declaration may issue different handles when they share a span table, while their declaration-local paths remain one fact.
12    #[must_use]
13    pub fn canonical_bytes(&self) -> Vec<u8> {
14        let mut material = vec![self.slot()];
15        match self {
16            Self::Unbounded { bound } => encode_bytes(bound.name().as_bytes(), &mut material),
17            Self::Unread { cause, path, at: _ } => {
18                encode_bytes(cause.name().as_bytes(), &mut material);
19                encode_token_path(path, &mut material);
20            }
21        }
22        material
23    }
24}