From 0ae4011c42a77b4a530bfe8731578e5f42e5405b Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 3 Aug 2026 00:05:22 +0800 Subject: feat(gen_program): add Entry struct and program constructors Add `Entry` struct with `pub(crate)` visibility for `inner` fields, plus `new()` and `this()` constructors on `ThisProgram` for docs.rs demonstration of the `gen_program!` macro expansion. --- mingling/src/gen_program.rs | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'mingling/src') diff --git a/mingling/src/gen_program.rs b/mingling/src/gen_program.rs index 144e081..18d9117 100644 --- a/mingling/src/gen_program.rs +++ b/mingling/src/gen_program.rs @@ -4,11 +4,21 @@ use mingling_core::ChainProcess; use mingling_core::Dispatcher; use mingling_core::Grouped; use mingling_core::Node; +use mingling_core::Program; use mingling_core::ProgramCollect; /// The next processing step for the current chain. pub type Next = ChainProcess; +/// The generic program entry point. +/// +/// This type is created by the `pack!` macro as a variant of the +/// program's output type set (`ThisProgram`). +pub struct Entry { + /// The arguments provided by the user + pub(crate) inner: Vec, +} + /// An enum used to record the set of program type IDs. /// /// It contains the IDs of all types for this program, registered by the `register_type!` macro. @@ -33,7 +43,7 @@ pub enum ThisProgram { /// program's output type set (`ThisProgram`). pub struct ErrorRendererNotFound { /// The name of the renderer that was not found - inner: String, + pub(crate) inner: String, } /// A struct representing a "dispatcher not found" error. @@ -42,7 +52,7 @@ pub struct ErrorRendererNotFound { /// program's output type set (`ThisProgram`). pub struct ErrorDispatcherNotFound { /// The arguments provided by the user - inner: Vec, + pub(crate) inner: Vec, } /// A struct representing an empty result. @@ -64,7 +74,7 @@ pub struct CMDCompletion; #[cfg(feature = "comp")] pub struct CompletionContext { /// The arguments provided by the user - inner: Vec, + pub(crate) inner: Vec, } /// Represents a completion suggestion result. @@ -97,6 +107,18 @@ impl Dispatcher for CMDCompletion { } } +// SAFETY: These implementations are provided for demonstration purposes only. +// The `member_id()` implementations map each type to its corresponding variant +// in the `ThisProgram` enum, and the IDs correctly correspond to the actual types. +// However, these are marked `unsafe` because the `Grouped` trait requires the +// implementor to guarantee that the type is the only one associated with the +// given enum variant — a guarantee that should be carefully verified in production code. +unsafe impl Grouped for Entry { + fn member_id() -> ThisProgram { + ThisProgram::Entry + } +} + // SAFETY: These implementations are provided for demonstration purposes only. // The `member_id()` implementations map each type to its corresponding variant // in the `ThisProgram` enum, and the IDs correctly correspond to the actual types. @@ -229,3 +251,15 @@ impl ProgramCollect for ThisProgram { todo!() } } + +impl ThisProgram { + /// Create a program through this ProgramCollect. + pub fn new() -> Program { + todo!() + } + + /// Get the global singleton of the current program. + pub fn this() -> &'static Program { + todo!() + } +} -- cgit