Skip to main content

buffa_codegen/adapters/
mod.rs

1//! Opt-in, descriptor-checked native adapters. Generated adapters are separate
2//! files: applications include them in the modules that own their native API.
3
4mod config;
5mod generate;
6mod options;
7
8pub use config::*;
9pub use generate::generate_adapters;
10pub(crate) use options::descriptor_options;
11
12/// Deterministic, allocation-free reason for rejecting adapter metadata.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14#[non_exhaustive]
15pub enum ErrorReason {
16    /// An adapter-specific plugin option has an invalid or repeated value.
17    InvalidPluginOption,
18    /// JSON has unknown/duplicate members, invalid types or excessive nesting.
19    InvalidManifest,
20    /// The manifest version is not supported.
21    UnsupportedVersion,
22    /// The manifest exceeds the encoded size limit.
23    ManifestTooLarge,
24    /// Reading the manifest failed.
25    ManifestIo,
26    /// A Rust name is not a usable identifier.
27    InvalidIdentifier,
28    /// A Rust path contains unsupported syntax.
29    InvalidRustPath,
30    /// An output filename is not a bare `.rs` sibling, or its destination
31    /// cannot be resolved safely.
32    InvalidOutput,
33    /// Two outputs have the same filename.
34    DuplicateOutput,
35    /// Native names, ports or variant names collide.
36    DuplicateName,
37    /// A named descriptor could not be found.
38    MissingDescriptor,
39    /// A descriptor has missing, ambiguous or invalid members.
40    InvalidDescriptor,
41    /// An adapter's authoritative source is outside this generation request.
42    GenerationScope,
43    /// A descriptor alternative was not explicitly mapped or rejected.
44    UncoveredCase,
45    /// An alternative is claimed more than once.
46    DuplicateCase,
47    /// A mapping names an alternative absent from the descriptor.
48    UnknownCase,
49    /// An unspecified zero value was mapped as an accepted alternative.
50    UnspecifiedCase,
51    /// An alias names no canonical variant or conflicts numerically.
52    InvalidNormalization,
53    /// External identities must be complete and unambiguous.
54    InvalidIdentifiers,
55    /// A payload has an incompatible type or capability.
56    InvalidPayload,
57    /// An owning payload attempted to borrow or own raw sensitive bytes.
58    OwnershipMismatch,
59    /// A oneof payload contains an unprojected field.
60    UncoveredField,
61    /// A payload claims a field outside its selected oneof alternative.
62    UnexpectedField,
63    /// Generated tokens did not form a Rust file.
64    InvalidSyntax,
65    /// Schema adapter options are enabled, but no requested file declares
66    /// them and no explicit configuration was supplied.
67    MissingSchemaAdapters,
68}
69
70/// Fixed adapter failure. Input names, paths and bytes are never retained.
71#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
72#[error("adapter generation failed: {reason:?}")]
73pub struct AdapterError {
74    /// Machine-readable failure reason.
75    pub reason: ErrorReason,
76}
77
78impl From<ErrorReason> for AdapterError {
79    fn from(reason: ErrorReason) -> Self {
80        Self { reason }
81    }
82}