browser_commander/playwright/protocol/
disposable.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 DisposableInitializer {}
16
17#[derive(Debug, Clone, PartialEq)]
19pub enum DisposableEvent {
20 Unknown {
22 method: String,
24 params: serde_json::Value,
26 },
27}
28
29impl ProtocolEvent for DisposableEvent {
30 fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
31 match method {
32 _ => Ok(Self::Unknown { method: method.to_string(), params }),
33 }
34 }
35}
36
37#[derive(Debug, Clone)]
39pub struct Disposable {
40 channel: Channel,
41}
42
43impl ChannelType for Disposable {
44 const INTERFACE: &'static str = "Disposable";
45 type Initializer = DisposableInitializer;
46 type Event = DisposableEvent;
47
48 fn accepts(interface: &str) -> bool {
49 matches!(interface, "Disposable")
50 }
51
52 fn from_channel(channel: Channel) -> Self {
53 Self { channel }
54 }
55
56 fn channel(&self) -> &Channel {
57 &self.channel
58 }
59}
60
61impl Disposable {
62 pub async fn dispose(&self) -> Result<(), ProtocolError> {
64 self.channel.send_no_result("dispose", &serde_json::json!({})).await
65 }
66}