use super::{
Anchoring, BUNDLE_PROFILE, CAPTURED_DECLARATION_PROFILE, CAPTURED_HELPER_PROFILE,
CLOSED_EXPANSION_PROFILE, CLOSURE_PROFILE, DECLARATION_DOCUMENTATION_PROFILE,
DECLARED_NAME_PROFILE, DIAGNOSTIC_RELATION_PROFILE, EXPLANATION_PROFILE,
GENERATED_UNIT_PROFILE, GENERATOR_VERSION_PROFILE, ORIGIN_NODE_PROFILE, PLAN_PROFILE,
PROJECTION_CONTENT_PROFILE, PROJECTION_INTENT_PROFILE, PROJECTION_KIND_PROFILE, Profile,
RENDERED_UNIT_PROFILE, Role,
};
impl Role {
pub const ALL: &'static [Self] = &[
Self::CapturedDeclaration,
Self::Plan,
Self::OriginNode,
Self::GeneratedUnit,
Self::RenderedUnit,
Self::OutputBytes,
Self::Bundle,
Self::Closure,
Self::ClosedExpansion,
Self::ProjectionIntent,
Self::Explanation,
Self::DeclarationDocumentation,
Self::DeclaredName,
Self::GeneratorVersion,
Self::DiagnosticRelation,
Self::CapturedHelper,
Self::ProjectionContent,
Self::ProjectionKind,
];
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::CapturedDeclaration => "captured-declaration",
Self::Plan => "plan",
Self::OriginNode => "origin-node",
Self::GeneratedUnit => "generated-unit",
Self::RenderedUnit => "rendered-unit",
Self::OutputBytes => "output-bytes",
Self::Bundle => "bundle",
Self::Closure => "closure",
Self::ClosedExpansion => "closed-expansion",
Self::ProjectionIntent => "projection-intent",
Self::Explanation => "explanation",
Self::DeclarationDocumentation => "declaration-documentation",
Self::DeclaredName => "declared-name",
Self::GeneratorVersion => "generator-version",
Self::DiagnosticRelation => "diagnostic-relation",
Self::CapturedHelper => "captured-helper",
Self::ProjectionContent => "projection-content",
Self::ProjectionKind => "projection-kind",
}
}
#[must_use]
pub const fn slot(self) -> u8 {
match self {
Self::CapturedDeclaration => 0,
Self::Plan => 1,
Self::OriginNode => 2,
Self::GeneratedUnit => 3,
Self::RenderedUnit => 4,
Self::OutputBytes => 5,
Self::Bundle => 6,
Self::Closure => 7,
Self::ClosedExpansion => 8,
Self::ProjectionIntent => 9,
Self::Explanation => 10,
Self::DeclarationDocumentation => 11,
Self::DeclaredName => 12,
Self::GeneratorVersion => 13,
Self::DiagnosticRelation => 14,
Self::CapturedHelper => 15,
Self::ProjectionContent => 16,
Self::ProjectionKind => 17,
}
}
#[must_use]
pub const fn described(self) -> &'static str {
match self {
Self::CapturedDeclaration => "the token material one expansion was handed",
Self::Plan => "one projection plan",
Self::OriginNode => "one node of the origin graph",
Self::GeneratedUnit => "one generated unit a plan declares it will materialize",
Self::RenderedUnit => "one rendered unit a renderer actually materialized",
Self::OutputBytes => "the canonical bytes of one rendered unit",
Self::Bundle => "one bundle materialized across a single publication boundary",
Self::Closure => "one proved closure between a plan and its rendering",
Self::ClosedExpansion => "one closed expansion",
Self::ProjectionIntent => "one projection intent, ahead of anything decided about it",
Self::Explanation => "one explanation answered over a plan and its closure",
Self::DeclarationDocumentation => {
"the documentation rows one captured declaration carries"
}
Self::DeclaredName => "one stable name this compiler wrote down",
Self::GeneratorVersion => "the generator's declared name and its shape position",
Self::DiagnosticRelation => {
"one refusal body or one established issue a diagnostic points at"
}
Self::CapturedHelper => "one helper attribute's material, read beside a declaration",
Self::ProjectionContent => "one kind-specific content commitment",
Self::ProjectionKind => "one owner-qualified projection kind",
}
}
#[must_use]
pub const fn profile(self) -> Profile {
match self {
Self::CapturedDeclaration => CAPTURED_DECLARATION_PROFILE,
Self::Plan => PLAN_PROFILE,
Self::OriginNode => ORIGIN_NODE_PROFILE,
Self::GeneratedUnit => GENERATED_UNIT_PROFILE,
Self::RenderedUnit | Self::OutputBytes => RENDERED_UNIT_PROFILE,
Self::Bundle => BUNDLE_PROFILE,
Self::Closure => CLOSURE_PROFILE,
Self::ClosedExpansion => CLOSED_EXPANSION_PROFILE,
Self::ProjectionIntent => PROJECTION_INTENT_PROFILE,
Self::Explanation => EXPLANATION_PROFILE,
Self::DeclarationDocumentation => DECLARATION_DOCUMENTATION_PROFILE,
Self::DeclaredName => DECLARED_NAME_PROFILE,
Self::GeneratorVersion => GENERATOR_VERSION_PROFILE,
Self::DiagnosticRelation => DIAGNOSTIC_RELATION_PROFILE,
Self::CapturedHelper => CAPTURED_HELPER_PROFILE,
Self::ProjectionContent => PROJECTION_CONTENT_PROFILE,
Self::ProjectionKind => PROJECTION_KIND_PROFILE,
}
}
}
const _: () = assert!(
slots_are_ordered(Role::ALL, 0),
"a role whose published slot disagrees with its position in the roster",
);
const fn slots_are_ordered(roles: &[Role], at: u8) -> bool {
match roles.split_first() {
None => true,
Some((first, rest)) => first.slot() == at && slots_are_ordered(rest, at.saturating_add(1)),
}
}
impl Anchoring {
#[must_use]
pub const fn slot(self) -> u8 {
match self {
Self::Rooted => 0,
Self::UnderOwner(_) => 1,
Self::UnderProjection(_) => 2,
}
}
#[must_use]
pub const fn commitment(&self) -> Option<&[u8; 32]> {
match self {
Self::Rooted => None,
Self::UnderOwner(anchor) | Self::UnderProjection(anchor) => Some(anchor),
}
}
}