Skip to main content

browser_commander/playwright/protocol/
artifact.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 `Artifact`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct ArtifactInitializer {
16    #[serde(rename = "absolutePath")]
17    pub absolute_path: String,
18}
19
20/// Result of `Artifact.pathAfterFinished`.
21#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
22pub struct ArtifactPathAfterFinishedResult {
23    #[serde(rename = "value")]
24    pub value: String,
25}
26
27/// Parameters of `Artifact.saveAs`.
28#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29pub struct ArtifactSaveAsParams {
30    #[serde(rename = "path")]
31    pub path: String,
32}
33
34/// Result of `Artifact.saveAsStream`.
35#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
36pub struct ArtifactSaveAsStreamResult {
37    #[serde(rename = "stream")]
38    pub stream: Ref<Stream>,
39}
40
41/// Result of `Artifact.failure`.
42#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
43pub struct ArtifactFailureResult {
44    #[serde(rename = "error", default, skip_serializing_if = "Option::is_none")]
45    pub error: Option<String>,
46}
47
48/// Result of `Artifact.stream`.
49#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
50pub struct ArtifactStreamResult {
51    #[serde(rename = "stream")]
52    pub stream: Ref<Stream>,
53}
54
55/// Events a `Artifact` channel can emit.
56#[derive(Debug, Clone, PartialEq)]
57pub enum ArtifactEvent {
58    /// An event this binding does not know (a newer driver).
59    Unknown {
60        /// Event name.
61        method: String,
62        /// Raw event parameters.
63        params: serde_json::Value,
64    },
65}
66
67impl ProtocolEvent for ArtifactEvent {
68    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
69        match method {
70            _ => Ok(Self::Unknown { method: method.to_string(), params }),
71        }
72    }
73}
74
75/// Channel for the `Artifact` interface (`artifact.yml`).
76#[derive(Debug, Clone)]
77pub struct Artifact {
78    channel: Channel,
79}
80
81impl ChannelType for Artifact {
82    const INTERFACE: &'static str = "Artifact";
83    type Initializer = ArtifactInitializer;
84    type Event = ArtifactEvent;
85
86    fn accepts(interface: &str) -> bool {
87        matches!(interface, "Artifact")
88    }
89
90    fn from_channel(channel: Channel) -> Self {
91        Self { channel }
92    }
93
94    fn channel(&self) -> &Channel {
95        &self.channel
96    }
97}
98
99impl Artifact {
100    /// `Artifact.pathAfterFinished` (internal).
101    pub async fn path_after_finished(&self) -> Result<ArtifactPathAfterFinishedResult, ProtocolError> {
102        self.channel.send("pathAfterFinished", &serde_json::json!({})).await
103    }
104
105    /// `Artifact.saveAs` (internal).
106    pub async fn save_as(&self, params: ArtifactSaveAsParams) -> Result<(), ProtocolError> {
107        self.channel.send_no_result("saveAs", &params).await
108    }
109
110    /// `Artifact.saveAsStream` (internal).
111    pub async fn save_as_stream(&self) -> Result<ArtifactSaveAsStreamResult, ProtocolError> {
112        self.channel.send("saveAsStream", &serde_json::json!({})).await
113    }
114
115    /// `Artifact.failure` (internal).
116    pub async fn failure(&self) -> Result<ArtifactFailureResult, ProtocolError> {
117        self.channel.send("failure", &serde_json::json!({})).await
118    }
119
120    /// `Artifact.stream` (internal).
121    pub async fn stream(&self) -> Result<ArtifactStreamResult, ProtocolError> {
122        self.channel.send("stream", &serde_json::json!({})).await
123    }
124
125    /// `Artifact.cancel` (internal).
126    pub async fn cancel(&self) -> Result<(), ProtocolError> {
127        self.channel.send_no_result("cancel", &serde_json::json!({})).await
128    }
129
130    /// `Artifact.delete` (internal).
131    pub async fn delete(&self) -> Result<(), ProtocolError> {
132        self.channel.send_no_result("delete", &serde_json::json!({})).await
133    }
134}