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