PipeTransport

Struct PipeTransport 

Source
pub struct PipeTransport<W, R>
where W: AsyncWrite + Unpin + Send, R: AsyncRead + Unpin + Send,
{ /* private fields */ }
Expand description

Pipe-based transport for communicating with Playwright server

This implementation matches playwright-python’s PipeTransport:

  • Messages are framed with 4-byte little-endian length prefix
  • Reads happen in a background task
  • Received messages are sent via mpsc channel

§Architecture

┌─────────────┐
│   Server    │
│   (Node.js) │
└──────┬──────┘
       │ stdio
       │
┌──────▼──────────────────────┐
│    PipeTransport            │
│  ┌────────┐   ┌──────────┐  │
│  │ Writer │   │  Reader  │  │
│  │ (send) │   │  (loop)  │  │
│  └────────┘   └──────────┘  │
└─────────────────┬───────────┘
                  │ mpsc channel
                  ▼
           ┌──────────────┐
           │  Connection  │
           │  (dispatch)  │
           └──────────────┘

§Platform-Specific Cleanup

Windows: The transport takes ownership of stdin/stdout from a Child process. When the transport is dropped, these handles are closed. On Windows, tokio uses a blocking threadpool for child process stdio, so proper cleanup requires that stdio handles be closed before terminating the parent process. See PlaywrightServer for the platform-specific cleanup logic.

Unix: Standard pipe cleanup applies - no special handling needed.

Implementations§

Source§

impl<W, R> PipeTransport<W, R>
where W: AsyncWrite + Unpin + Send, R: AsyncRead + Unpin + Send,

Source

pub fn new(stdin: W, stdout: R) -> (Self, UnboundedReceiver<JsonValue>)

Create a new pipe transport from child process stdio handles

§Arguments
  • stdin - Child process stdin for sending messages
  • stdout - Child process stdout for receiving messages

Returns a tuple of (PipeTransport, message receiver channel)

§Example
let mut child = Command::new("node")
    .arg("cli.js")
    .stdin(std::process::Stdio::piped())
    .stdout(std::process::Stdio::piped())
    .spawn()?;

let stdin = child.stdin.take().unwrap();
let stdout = child.stdout.take().unwrap();

let (mut transport, mut rx) = PipeTransport::new(stdin, stdout);

// Spawn read loop
tokio::spawn(async move {
    transport.run().await
});

// Receive messages
while let Some(message) = rx.recv().await {
    println!("Received: {:?}", message);
}
Source

pub fn into_parts(self) -> (W, PipeTransportReceiver<R>)

Split the transport into stdin and the rest

This allows Connection to hold stdin separately (for sending) while run() owns stdout (for receiving).

§Returns

Returns (stdin, self_without_stdin) where self_without_stdin can still run the receive loop but cannot send.

Source

pub async fn run(&mut self) -> Result<()>

Run the message read loop

This continuously reads messages from the server and sends them to the message channel. Matches playwright-python’s run() method.

For messages larger than 32KB, reads in chunks to reduce peak memory usage. Matches playwright-python’s chunked reading strategy.

The loop will run until:

  • An error occurs
  • The stdout stream is closed
  • The message channel is dropped
§Errors

Returns an error if reading from stdout fails or if message parsing fails.

Trait Implementations§

Source§

impl<W, R> Transport for PipeTransport<W, R>
where W: AsyncWrite + Unpin + Send + Sync, R: AsyncRead + Unpin + Send + Sync,

Source§

async fn send(&mut self, message: JsonValue) -> Result<()>

Send a JSON message to the server

Auto Trait Implementations§

§

impl<W, R> Freeze for PipeTransport<W, R>
where W: Freeze, R: Freeze,

§

impl<W, R> RefUnwindSafe for PipeTransport<W, R>

§

impl<W, R> Send for PipeTransport<W, R>

§

impl<W, R> Sync for PipeTransport<W, R>
where W: Sync, R: Sync,

§

impl<W, R> Unpin for PipeTransport<W, R>

§

impl<W, R> UnwindSafe for PipeTransport<W, R>
where W: UnwindSafe, R: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more