Skip to main content

StdioTransport

Struct StdioTransport 

Source
pub struct StdioTransport { /* private fields */ }
Expand description

The newline-framed MSP transport over a spawned host’s stdin and stdout.

Hand it the pipes from MuseChild::take_stdin and MuseChild::take_stdout, and Connection::new gives you a raw connection to that host. MuseClient::spawn uses this same transport.

The transport owns the host’s stdin, so close the connection before MuseChild::close: closing it sends the host EOF, and the host exits. Closing the host first sends no EOF, so it waits out the shutdown timeout and then ends the host by signal.

use muse_code_sdk::connection::{Connection, StdioTransport};
use muse_code_sdk::spawn::{SpawnOptions, spawn_muse};

let mut host = spawn_muse(SpawnOptions::default())?;
let (stdin, stdout) = (host.take_stdin(), host.take_stdout());
let transport = StdioTransport::new(stdin.ok_or("no stdin")?, stdout.ok_or("no stdout")?);
let (connection, driver) = Connection::new(transport);
tokio::spawn(driver.run());
// ... the handshake, then requests ...
connection.close().await;
host.close().await?;

Implementations§

Source§

impl StdioTransport

Source

pub fn new(stdin: ChildStdin, stdout: ChildStdout) -> Self

Wraps a spawned host’s stdin and stdout.

Trait Implementations§

Source§

impl Debug for StdioTransport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DuplexTransport for StdioTransport

Source§

fn read_chunk( &mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + '_>>

Returns the next decoded chunk, or None after transport EOF.
Source§

fn write( &mut self, frame: &str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + '_>>

Submits an already newline-framed outgoing message.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.