use crate::bounded::{Bounded, Capped, NonEmpty};
use crate::explanation::ASSUMPTION_LIMIT;
use crate::identity::{OwnerFact, OwnerIdentity};
#[path = "type_guard.rs"]
mod guard;
pub const CODEC_MEMBER_LIMIT: usize = 64;
pub const CODEC_PATH_SEGMENT_LIMIT: usize = crate::token::RENDERED_PATH_SEGMENT_LIMIT;
pub const CODEC_ISSUE_LIMIT: usize = 64;
pub const ENCODE_ROAD: &str = "encode_canonical";
pub const DECODE_ROAD: &str = "decode_canonical";
pub const ROSTER_CONSTANT: &str = "ALL";
pub const SLOT_ROAD: &str = "slot";
crate::roster! {
pub enum Cardinality {
Required = "required",
Optional = "optional",
Repeated = "repeated",
}
}
crate::roster! {
pub enum CodecMemberShape {
Count = "count",
Bytes = "bytes",
Text = "text",
ClosedChoice = "closed-choice",
Nested = "nested",
}
}
crate::roster! {
pub enum CodecDirection {
Encode = "encode",
Decode = "decode",
RoundTrip = "round-trip",
}
}
crate::roster! {
pub enum PathRooting {
CrateAbsolute = "crate-absolute",
InScope = "in-scope",
SelfScoped = "self-scoped",
ParentScoped = "parent-scoped",
}
}
crate::roster! {
pub enum DecodeRefusal {
Truncated = "Truncated",
LengthPastRemaining = "LengthPastRemaining",
LengthPastAddressableWidth = "LengthPastAddressableWidth",
CountPastDeclaredWidth = "CountPastDeclaredWidth",
TextNotUtf8 = "TextNotUtf8",
MemberNotAdmitted = "MemberNotAdmitted",
SlotNotAdmitted = "SlotNotAdmitted",
NestedMemberRefused = "NestedMemberRefused",
PresenceNotAdmitted = "PresenceNotAdmitted",
TrailingBytes = "TrailingBytes",
NotAssembled = "NotAssembled",
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MemberContract {
pub shape: CodecMemberShape,
pub encode_road: &'static str,
pub decode_road: &'static str,
}
#[derive(Clone, Copy)]
pub(super) enum WriteRoad {
Count,
Bytes,
Text,
ClosedChoice,
Nested,
}
#[derive(Clone, Copy)]
pub(super) enum ReadRoad {
Count,
Bytes,
Text,
ClosedChoice,
Nested,
}
#[derive(Clone, Copy)]
pub(super) struct RenderingContract {
pub(super) bill: MemberContract,
pub(super) write: WriteRoad,
pub(super) read: ReadRoad,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CodecTypePath {
rooting: PathRooting,
segments: NonEmpty<String, CODEC_PATH_SEGMENT_LIMIT>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CodecMember {
spelling: String,
held_as: CodecTypePath,
shape: CodecMemberShape,
cardinality: Cardinality,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AssemblyPosture {
Total,
Checked {
refusal: CodecTypePath,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CodecAssembly {
road: String,
posture: AssemblyPosture,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CodecShape {
owner: CodecTypePath,
refusal: String,
assembly: CodecAssembly,
members: NonEmpty<CodecMember, CODEC_MEMBER_LIMIT>,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ModuleSpelling {
spelling: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CodecPlacement {
AtDeclarationSite,
PublishedModule {
spelling: ModuleSpelling,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CodecContent {
pub shape: CodecShape,
pub direction: CodecDirection,
pub placement: CodecPlacement,
pub schema: Option<OwnerIdentity>,
pub byte_role: Option<OwnerIdentity>,
pub assumptions: Bounded<OwnerFact, ASSUMPTION_LIMIT>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CodecProjection;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CodecIssue {
PathSegmentsAbsent,
SegmentNotAnIdentifier {
segment: String,
},
PathSegmentsUnbounded {
bound: u64,
observed: u64,
},
MemberSpellingAbsent,
MemberSpellingNotAnIdentifier {
spelling: String,
},
MemberSpellingDoubled {
spelling: String,
},
MemberShadowsBinding {
spelling: String,
binding: &'static str,
},
AssemblyRoadAbsent,
AssemblyRoadNotAnIdentifier {
spelling: String,
},
RefusalSpellingNotAnIdentifier {
spelling: String,
},
ModuleSpellingNotAnIdentifier {
spelling: String,
},
MembersAbsent,
MembersUnbounded {
bound: u64,
observed: u64,
},
}
#[must_use = "a codec refusal names the exact seat the declaration did not fill"]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CodecError {
body: Capped<CodecIssue, CODEC_ISSUE_LIMIT>,
}
pub use guard::{rendered_identifier, rendered_name};