rustenium_bidi_definitions/log/
types.rs1use serde::{Deserialize, Serialize};
2#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
3pub enum Level {
4 #[serde(rename = "debug")]
5 Debug,
6 #[serde(rename = "info")]
7 Info,
8 #[serde(rename = "warn")]
9 Warn,
10 #[serde(rename = "error")]
11 Error,
12}
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14#[serde(untagged)]
15pub enum Entry {
16 GenericLogEntry(GenericLogEntry),
17 ConsoleLogEntry(ConsoleLogEntry),
18 JavascriptLogEntry(JavascriptLogEntry),
19}
20impl From<GenericLogEntry> for Entry {
21 fn from(v: GenericLogEntry) -> Self {
22 Entry::GenericLogEntry(v)
23 }
24}
25impl TryFrom<Entry> for GenericLogEntry {
26 type Error = Entry;
27 fn try_from(e: Entry) -> Result<Self, Self::Error> {
28 match e {
29 Entry::GenericLogEntry(inner) => Ok(inner),
30 other => Err(other),
31 }
32 }
33}
34impl From<ConsoleLogEntry> for Entry {
35 fn from(v: ConsoleLogEntry) -> Self {
36 Entry::ConsoleLogEntry(v)
37 }
38}
39impl TryFrom<Entry> for ConsoleLogEntry {
40 type Error = Entry;
41 fn try_from(e: Entry) -> Result<Self, Self::Error> {
42 match e {
43 Entry::ConsoleLogEntry(inner) => Ok(inner),
44 other => Err(other),
45 }
46 }
47}
48impl From<JavascriptLogEntry> for Entry {
49 fn from(v: JavascriptLogEntry) -> Self {
50 Entry::JavascriptLogEntry(v)
51 }
52}
53impl TryFrom<Entry> for JavascriptLogEntry {
54 type Error = Entry;
55 fn try_from(e: Entry) -> Result<Self, Self::Error> {
56 match e {
57 Entry::JavascriptLogEntry(inner) => Ok(inner),
58 other => Err(other),
59 }
60 }
61}
62#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
63pub struct BaseLogEntry {
64 #[serde(rename = "level")]
65 pub level: Level,
66 #[serde(rename = "source")]
67 pub source: crate::script::types::Source,
68 #[serde(rename = "text")]
69 #[serde(skip_serializing_if = "Option::is_none")]
70 #[serde(default)]
71 pub text: Option<String>,
72 #[serde(rename = "timestamp")]
73 pub timestamp: u64,
74 #[serde(rename = "stackTrace")]
75 #[serde(skip_serializing_if = "Option::is_none")]
76 #[serde(default)]
77 pub stack_trace: Option<crate::script::types::StackTrace>,
78}
79impl BaseLogEntry {
80 pub fn new(
81 level: impl Into<Level>,
82 source: impl Into<crate::script::types::Source>,
83 timestamp: impl Into<u64>,
84 ) -> Self {
85 Self {
86 level: level.into(),
87 source: source.into(),
88 timestamp: timestamp.into(),
89 text: None,
90 stack_trace: None,
91 }
92 }
93}
94impl BaseLogEntry {
95 pub const IDENTIFIER: &'static str = "log.BaseLogEntry";
96 pub const DOMAIN_DIRECTION: &'static str = "local";
97 pub fn identifier(&self) -> &'static str {
98 Self::IDENTIFIER
99 }
100}
101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
102pub struct GenericLogEntry {
103 #[serde(flatten)]
104 #[serde(default)]
105 pub base_log_entry: BaseLogEntry,
106 #[serde(rename = "type")]
107 pub r#type: String,
108}
109impl GenericLogEntry {
110 pub fn new(base_log_entry: impl Into<BaseLogEntry>, r#type: impl Into<String>) -> Self {
111 Self {
112 base_log_entry: base_log_entry.into(),
113 r#type: r#type.into(),
114 }
115 }
116}
117impl GenericLogEntry {
118 pub const IDENTIFIER: &'static str = "log.GenericLogEntry";
119 pub const DOMAIN_DIRECTION: &'static str = "local";
120 pub fn identifier(&self) -> &'static str {
121 Self::IDENTIFIER
122 }
123}
124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
125pub struct ConsoleLogEntry {
126 #[serde(flatten)]
127 #[serde(default)]
128 pub base_log_entry: BaseLogEntry,
129 #[serde(rename = "type")]
130 pub r#type: ConsoleLogEntryType,
131 #[serde(rename = "method")]
132 pub method: String,
133 #[serde(rename = "args")]
134 #[serde(skip_serializing_if = "Vec::is_empty")]
135 pub args: Vec<crate::script::types::RemoteValue>,
136}
137#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
138pub enum ConsoleLogEntryType {
139 #[serde(rename = "console")]
140 Console,
141}
142impl ConsoleLogEntry {
143 pub fn new(
144 base_log_entry: impl Into<BaseLogEntry>,
145 r#type: impl Into<ConsoleLogEntryType>,
146 method: impl Into<String>,
147 args: Vec<crate::script::types::RemoteValue>,
148 ) -> Self {
149 Self {
150 base_log_entry: base_log_entry.into(),
151 r#type: r#type.into(),
152 method: method.into(),
153 args,
154 }
155 }
156}
157impl ConsoleLogEntry {
158 pub const IDENTIFIER: &'static str = "log.ConsoleLogEntry";
159 pub const DOMAIN_DIRECTION: &'static str = "local";
160 pub fn identifier(&self) -> &'static str {
161 Self::IDENTIFIER
162 }
163}
164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
165pub struct JavascriptLogEntry {
166 #[serde(flatten)]
167 #[serde(default)]
168 pub base_log_entry: BaseLogEntry,
169 #[serde(rename = "type")]
170 pub r#type: JavascriptLogEntryType,
171}
172#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
173pub enum JavascriptLogEntryType {
174 #[serde(rename = "javascript")]
175 Javascript,
176}
177impl JavascriptLogEntry {
178 pub fn new(
179 base_log_entry: impl Into<BaseLogEntry>,
180 r#type: impl Into<JavascriptLogEntryType>,
181 ) -> Self {
182 Self {
183 base_log_entry: base_log_entry.into(),
184 r#type: r#type.into(),
185 }
186 }
187}
188impl JavascriptLogEntry {
189 pub const IDENTIFIER: &'static str = "log.JavascriptLogEntry";
190 pub const DOMAIN_DIRECTION: &'static str = "local";
191 pub fn identifier(&self) -> &'static str {
192 Self::IDENTIFIER
193 }
194}