Skip to main content

browser_commander/playwright/protocol/
writable_stream.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Initializer the driver sends when it creates a `WritableStream`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct WritableStreamInitializer {}
16
17/// Parameters of `WritableStream.write`.
18#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct WritableStreamWriteParams {
20    #[serde(rename = "binary")]
21    pub binary: Binary,
22}
23
24/// Events a `WritableStream` channel can emit.
25#[derive(Debug, Clone, PartialEq)]
26pub enum WritableStreamEvent {
27    /// An event this binding does not know (a newer driver).
28    Unknown {
29        /// Event name.
30        method: String,
31        /// Raw event parameters.
32        params: serde_json::Value,
33    },
34}
35
36impl ProtocolEvent for WritableStreamEvent {
37    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
38        match method {
39            _ => Ok(Self::Unknown { method: method.to_string(), params }),
40        }
41    }
42}
43
44/// Channel for the `WritableStream` interface (`artifact.yml`).
45#[derive(Debug, Clone)]
46pub struct WritableStream {
47    channel: Channel,
48}
49
50impl ChannelType for WritableStream {
51    const INTERFACE: &'static str = "WritableStream";
52    type Initializer = WritableStreamInitializer;
53    type Event = WritableStreamEvent;
54
55    fn accepts(interface: &str) -> bool {
56        matches!(interface, "WritableStream")
57    }
58
59    fn from_channel(channel: Channel) -> Self {
60        Self { channel }
61    }
62
63    fn channel(&self) -> &Channel {
64        &self.channel
65    }
66}
67
68impl WritableStream {
69    /// `WritableStream.write` (internal).
70    pub async fn write(&self, params: WritableStreamWriteParams) -> Result<(), ProtocolError> {
71        self.channel.send_no_result("write", &params).await
72    }
73
74    /// `WritableStream.close` (internal).
75    pub async fn close(&self) -> Result<(), ProtocolError> {
76        self.channel.send_no_result("close", &serde_json::json!({})).await
77    }
78}