browser_commander/playwright/protocol/
writable_stream.rs1#![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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct WritableStreamInitializer {}
16
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct WritableStreamWriteParams {
20 #[serde(rename = "binary")]
21 pub binary: Binary,
22}
23
24#[derive(Debug, Clone, PartialEq)]
26pub enum WritableStreamEvent {
27 Unknown {
29 method: String,
31 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#[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 pub async fn write(&self, params: WritableStreamWriteParams) -> Result<(), ProtocolError> {
71 self.channel.send_no_result("write", ¶ms).await
72 }
73
74 pub async fn close(&self) -> Result<(), ProtocolError> {
76 self.channel.send_no_result("close", &serde_json::json!({})).await
77 }
78}