From 332ee84b59f33e3a3f1cb109e02a1c0c9fe108cd Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 20 Jun 2026 05:34:51 +0800 Subject: Add output protocol trait and implementations --- src/output_protocol.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/output_protocol.rs (limited to 'src/output_protocol.rs') diff --git a/src/output_protocol.rs b/src/output_protocol.rs new file mode 100644 index 0000000..87e2400 --- /dev/null +++ b/src/output_protocol.rs @@ -0,0 +1,50 @@ +use std::sync::Arc; + +pub mod ipc; +pub mod stderr; +pub mod stdout; +pub mod tcp; +pub mod udp; +pub mod udp_broadcast; + +pub use ipc::*; +pub use stderr::*; +pub use stdout::*; +pub use tcp::*; +pub use udp::*; +pub use udp_broadcast::*; + +/// Defines the protocol for an output channel that can be initialized and used to send messages. +/// +/// Implementors of this trait provide the underlying mechanism for message delivery, +/// such as writing to stdout, a file, or a network socket. +/// +/// # Type Parameters +/// +/// The trait methods return `impl Future + Send + Sync`, allowing +/// asynchronous implementations that can be shared across threads. +pub trait OutputProtocol { + /// Initializes the output channel. + /// + /// This method consumes `self`, indicating it should be called once during setup + /// to prepare the output resource (e.g., opening a file, establishing a connection). + /// + /// # Returns + /// + /// A future that resolves when initialization is complete. + fn init(self) -> impl Future + Send + Sync; + + /// Sends a message string through the output channel. + /// + /// This method takes `self: Arc`, allowing the output channel to be shared + /// across multiple concurrent senders (e.g., in multi-threaded or async contexts). + /// + /// # Arguments + /// + /// * `str` - The string message to send. + /// + /// # Returns + /// + /// A future that resolves when the message has been sent. + fn send(self: Arc, str: &str) -> impl Future + Send + Sync; +} -- cgit