playwright_rs/protocol/
artifact.rs1use crate::error::Result;
10use crate::server::channel_owner::{ChannelOwner, ChannelOwnerImpl, ParentOrConnection};
11use serde_json::Value;
12use std::any::Any;
13use std::sync::Arc;
14
15#[derive(Clone)]
20pub struct Artifact {
21 base: ChannelOwnerImpl,
22}
23
24impl Artifact {
25 pub fn new(
27 parent: Arc<dyn ChannelOwner>,
28 type_name: String,
29 guid: Arc<str>,
30 initializer: Value,
31 ) -> Result<Self> {
32 let base = ChannelOwnerImpl::new(
33 ParentOrConnection::Parent(parent),
34 type_name,
35 guid,
36 initializer,
37 );
38
39 Ok(Self { base })
40 }
41}
42
43impl ChannelOwner for Artifact {
44 fn guid(&self) -> &str {
45 self.base.guid()
46 }
47
48 fn type_name(&self) -> &str {
49 self.base.type_name()
50 }
51
52 fn parent(&self) -> Option<Arc<dyn ChannelOwner>> {
53 self.base.parent()
54 }
55
56 fn connection(&self) -> Arc<dyn crate::server::connection::ConnectionLike> {
57 self.base.connection()
58 }
59
60 fn initializer(&self) -> &Value {
61 self.base.initializer()
62 }
63
64 fn channel(&self) -> &crate::server::channel::Channel {
65 self.base.channel()
66 }
67
68 fn dispose(&self, reason: crate::server::channel_owner::DisposeReason) {
69 self.base.dispose(reason)
70 }
71
72 fn adopt(&self, child: Arc<dyn ChannelOwner>) {
73 self.base.adopt(child)
74 }
75
76 fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>) {
77 self.base.add_child(guid, child)
78 }
79
80 fn remove_child(&self, guid: &str) {
81 self.base.remove_child(guid)
82 }
83
84 fn on_event(&self, _method: &str, _params: Value) {
85 }
87
88 fn was_collected(&self) -> bool {
89 self.base.was_collected()
90 }
91
92 fn as_any(&self) -> &dyn Any {
93 self
94 }
95}
96
97impl std::fmt::Debug for Artifact {
98 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99 f.debug_struct("Artifact")
100 .field("guid", &self.guid())
101 .finish()
102 }
103}