pub struct StdioSink<W> { /* private fields */ }Expand description
Writes framed documents to the peer, and to nothing else.
§Examples
use protocol_droid::adapters::primary::stdio::{StdioConfig, StdioSink};
use protocol_droid::domain::MaxFrameSize;
let config = StdioConfig::new(MaxFrameSize::new(1024)?);
let sink = StdioSink::new(tokio::io::sink(), config);
// One line, one terminator, and nothing else on the stream.
sink.send(r#"{"jsonrpc":"2.0","id":1,"result":null}"#).await?;Implementations§
Source§impl<W> StdioSink<W>
impl<W> StdioSink<W>
Sourcepub fn new(stream: W, config: StdioConfig) -> Self
pub fn new(stream: W, config: StdioConfig) -> Self
Wraps a stream, refusing replies above the configured ceiling.
Sourcepub const fn limit(&self) -> MaxFrameSize
pub const fn limit(&self) -> MaxFrameSize
The ceiling this sink refuses replies above.
Source§impl<W> StdioSink<W>where
W: AsyncWrite + Unpin,
impl<W> StdioSink<W>where
W: AsyncWrite + Unpin,
Sourcepub async fn send(&self, document: &str) -> Result<(), StdioError>
pub async fn send(&self, document: &str) -> Result<(), StdioError>
Frames document and writes it as one line.
§Errors
StdioError::ReplyTooLarge when the document is longer than the
ceiling, in which case nothing is written — not a prefix, not a
truncated line. StdioError::Transport when the stream refuses the
bytes.
Trait Implementations§
Source§impl<W> FrameSink for StdioSink<W>
impl<W> FrameSink for StdioSink<W>
Source§async fn send(&self, frame: &str) -> Result<(), SinkError>
async fn send(&self, frame: &str) -> Result<(), SinkError>
Writes one encoded frame.
Collapses StdioError into the port’s unit SinkError, because the
session engine is protocol-neutral and must not learn which transport it
happens to be driving. That collapse is the mapping this boundary exists
to perform — the specific reason was already decided by the time the
engine asked, and a caller that needs it drives
StdioSink::send directly.
§Errors
SinkError when the frame did not reach the peer.