Skip to main content

js_protocol/
lib.rs

1#![allow(non_snake_case)]
2#![allow(unused_imports)]
3#![allow(dead_code)]
4
5use serde::{Serialize, Deserialize};
6use serde_json::Value as JsonValue;
7
8/// Trait for CDP commands that associate parameters with a method name and response type.
9pub trait CdpCommand: Serialize {
10    const METHOD: &'static str;
11    type Response: for<'de> Deserialize<'de>;
12}
13
14/// A generic CDP command envelope.
15#[derive(Serialize)]
16pub struct Command<'a, T: CdpCommand> {
17    pub id: u64,
18    pub method: &'static str,
19    pub params: &'a T,
20}
21
22impl<'a, T: CdpCommand> Command<'a, T> {
23    pub fn new(id: u64, params: &'a T) -> Self {
24        Self { id, method: T::METHOD, params }
25    }
26}
27
28/// A generic CDP response envelope.
29#[derive(Deserialize, Debug)]
30pub struct Response<T> {
31    pub id: u64,
32    pub result: T,
33}
34
35/// An empty response for commands that don't return anything.
36#[derive(Deserialize, Debug, Clone, Default)]
37pub struct EmptyReturns {}
38
39#[cfg(feature = "console")]
40pub mod console;
41#[cfg(feature = "debugger")]
42pub mod debugger;
43#[cfg(feature = "heapprofiler")]
44pub mod heapprofiler;
45#[cfg(feature = "profiler")]
46pub mod profiler;
47#[cfg(feature = "runtime")]
48pub mod runtime;
49#[cfg(feature = "schema")]
50pub mod schema;