Skip to main content

browser_commander/playwright/protocol/
disposable.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 `Disposable`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct DisposableInitializer {}
16
17/// Events a `Disposable` channel can emit.
18#[derive(Debug, Clone, PartialEq)]
19pub enum DisposableEvent {
20    /// An event this binding does not know (a newer driver).
21    Unknown {
22        /// Event name.
23        method: String,
24        /// Raw event parameters.
25        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/// Channel for the `Disposable` interface (`core.yml`).
38#[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    /// `Disposable.dispose` (internal).
63    pub async fn dispose(&self) -> Result<(), ProtocolError> {
64        self.channel.send_no_result("dispose", &serde_json::json!({})).await
65    }
66}