browser-commander 0.14.0

Universal browser automation library that supports multiple browser engines with a unified API
Documentation
// @generated by scripts/generate-playwright-protocol.mjs from
// rust/protocol/playwright/*.yml. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports)]

use serde::{Deserialize, Serialize};

use super::*;
use crate::playwright::connection::{
    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};

/// Initializer the driver sends when it creates a `Disposable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisposableInitializer {}

/// Events a `Disposable` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum DisposableEvent {
    /// An event this binding does not know (a newer driver).
    Unknown {
        /// Event name.
        method: String,
        /// Raw event parameters.
        params: serde_json::Value,
    },
}

impl ProtocolEvent for DisposableEvent {
    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
        match method {
            _ => Ok(Self::Unknown { method: method.to_string(), params }),
        }
    }
}

/// Channel for the `Disposable` interface (`core.yml`).
#[derive(Debug, Clone)]
pub struct Disposable {
    channel: Channel,
}

impl ChannelType for Disposable {
    const INTERFACE: &'static str = "Disposable";
    type Initializer = DisposableInitializer;
    type Event = DisposableEvent;

    fn accepts(interface: &str) -> bool {
        matches!(interface, "Disposable")
    }

    fn from_channel(channel: Channel) -> Self {
        Self { channel }
    }

    fn channel(&self) -> &Channel {
        &self.channel
    }
}

impl Disposable {
    /// `Disposable.dispose` (internal).
    pub async fn dispose(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("dispose", &serde_json::json!({})).await
    }
}