pub struct ByteStreams<OB, IB> {
pub outgoing: OB,
pub incoming: IB,
}Expand description
A component that communicates over byte streams (stdin/stdout, sockets, pipes, etc.).
ByteStreams implements the Component trait for any pair of AsyncRead and AsyncWrite
streams, handling serialization of JSON-RPC messages to/from newline-delimited JSON.
This is the standard way to communicate with external processes or network connections.
§Use Cases
- Stdio communication: Connect to agents or proxies via stdin/stdout
- Network sockets: TCP, Unix domain sockets, or other stream-based protocols
- Named pipes: Cross-process communication on the same machine
- File I/O: Reading from and writing to file descriptors
§Example
Connecting to an agent via stdio:
use sacp::link::UntypedLink;
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
let component = ByteStreams::new(
tokio::io::stdout().compat_write(),
tokio::io::stdin().compat(),
);
// Use as a component in a connection
sacp::link::UntypedLink::builder()
.name("my-client")
.serve(component)
.await?;Fields§
§outgoing: OBOutgoing byte stream (where we write serialized messages)
incoming: IBIncoming byte stream (where we read and parse messages)
Implementations§
Source§impl<OB, IB> ByteStreams<OB, IB>
impl<OB, IB> ByteStreams<OB, IB>
Trait Implementations§
Auto Trait Implementations§
impl<OB, IB> Freeze for ByteStreams<OB, IB>
impl<OB, IB> RefUnwindSafe for ByteStreams<OB, IB>where
OB: RefUnwindSafe,
IB: RefUnwindSafe,
impl<OB, IB> Send for ByteStreams<OB, IB>
impl<OB, IB> Sync for ByteStreams<OB, IB>
impl<OB, IB> Unpin for ByteStreams<OB, IB>
impl<OB, IB> UnwindSafe for ByteStreams<OB, IB>where
OB: UnwindSafe,
IB: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more