v0.2.14-pre.003
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-program-api/src/lib.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![deny(unreachable_pub)]
|
||||
@@ -7,11 +7,17 @@
|
||||
|
||||
//! Open Program contracts shared by KSP and external Program implementations.
|
||||
//!
|
||||
//! This initial scaffold exposes only the Core and Interface types selected by
|
||||
//! the `0.2.14` API model. Decoder behavior, recognition, decode outcomes,
|
||||
//! registries, codecs, runtime logging and execution preparation are added only
|
||||
//! by later contracts when their ownership is justified.
|
||||
//! The foundation exposes Core/Interface types plus the minimal instruction
|
||||
//! recognition and decode-outcome vocabulary. Decoder behavior, registries,
|
||||
//! codecs, runtime logging and execution preparation are added only by later
|
||||
//! contracts when their ownership is justified.
|
||||
|
||||
mod program_instruction_decode;
|
||||
|
||||
/// Result of a successful Program instruction decode attempt.
|
||||
pub use self::program_instruction_decode::ProgramInstructionDecodeOutcome;
|
||||
/// Recognition strength reported by one Program instruction implementation.
|
||||
pub use self::program_instruction_decode::ProgramInstructionRecognition;
|
||||
/// Common KSP error type used by Program-facing contracts.
|
||||
pub use ksp_core_lib::Error;
|
||||
/// Stable structured code identifying a KSP error category and condition.
|
||||
|
||||
50
crates/ksp-program-api/src/program_instruction_decode.rs
Normal file
50
crates/ksp-program-api/src/program_instruction_decode.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
// file: crates/ksp-program-api/src/program_instruction_decode.rs
|
||||
// version: 1
|
||||
|
||||
/// Recognition strength reported by one Program instruction implementation.
|
||||
///
|
||||
/// Recognition is intentionally instruction-local. It does not encode registry
|
||||
/// priority, a persisted proof, a textual discriminator or a global Program
|
||||
/// kind. [`Self::ExactMatch`] is an assertion made by the implementation for
|
||||
/// the current instruction, while [`Self::ProgramMatch`] only establishes the
|
||||
/// Program-level match.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum ProgramInstructionRecognition {
|
||||
/// The implementation does not claim the instruction.
|
||||
NoMatch,
|
||||
/// The Program or Program family matches, but the instruction is not proven exact.
|
||||
ProgramMatch,
|
||||
/// The implementation claims an exact instruction-local match.
|
||||
ExactMatch,
|
||||
}
|
||||
|
||||
/// Result of a successful Program instruction decode attempt.
|
||||
///
|
||||
/// Decode failures are represented by the surrounding KSP [`crate::Result`],
|
||||
/// not by a parallel failure variant. `Unsupported` is reserved for a known
|
||||
/// Program instruction that the implementation deliberately does not decode.
|
||||
///
|
||||
/// The custom [`std::fmt::Debug`] implementation never formats the `Decoded`
|
||||
/// value, so external decoded payloads are not exposed accidentally through
|
||||
/// generic diagnostics.
|
||||
#[non_exhaustive]
|
||||
pub enum ProgramInstructionDecodeOutcome<Decoded> {
|
||||
/// The instruction was decoded into the implementation-owned output type.
|
||||
Decoded(Decoded),
|
||||
/// The instruction is known but unsupported by this decode capability.
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
impl<Decoded> std::fmt::Debug for ProgramInstructionDecodeOutcome<Decoded> {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Decoded(_) => return formatter.write_str("Decoded"),
|
||||
Self::Unsupported => return formatter.write_str("Unsupported"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../unit_tests/program_instruction_decode.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user