dap_reactor/models/
set_breakpoints.rs1use super::*;
2
3use crate::prelude::Breakpoint;
4use crate::prelude::Source;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct SetBreakpointsArguments {
8 pub source: Source,
9 pub breakpoints: Vec<SourceBreakpoint>,
10 pub lines: Vec<u64>,
11 pub source_modified: bool,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct SourceBreakpoint {
16 pub line: u64,
17 pub column: Option<u64>,
18 pub condition: Option<String>,
19 pub hit_condition: Option<String>,
20 pub log_message: Option<String>,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct SetBreakpointsResponse {
25 pub breakpoints: Vec<Breakpoint>,
26}
27
28impl From<SetBreakpointsArguments> for Value {
29 fn from(args: SetBreakpointsArguments) -> Self {
30 let SetBreakpointsArguments {
31 source,
32 breakpoints,
33 lines,
34 source_modified,
35 } = args;
36
37 let source = utils::attribute("source", source);
38 let breakpoints = utils::attribute_optional("breakpoints", Some(breakpoints));
39 let lines = utils::attribute_optional("lines", Some(lines));
40 let source_modified = utils::attribute_bool_optional("sourceModified", source_modified);
41
42 utils::finalize_object(
43 source
44 .chain(breakpoints)
45 .chain(lines)
46 .chain(source_modified),
47 )
48 }
49}
50
51impl TryFrom<&Map<String, Value>> for SetBreakpointsArguments {
52 type Error = Error;
53
54 fn try_from(map: &Map<String, Value>) -> Result<Self, Self::Error> {
55 let source = utils::get_object(map, "source")?;
56 let breakpoints = utils::get_array_optional(map, "breakpoints")?;
57 let lines = utils::get_array_of_u64_optional(map, "lines")?;
58 let source_modified = utils::get_bool_optional(map, "sourceModified")?;
59
60 Ok(Self {
61 source,
62 breakpoints,
63 lines,
64 source_modified,
65 })
66 }
67}
68
69impl From<SourceBreakpoint> for Value {
70 fn from(args: SourceBreakpoint) -> Self {
71 let SourceBreakpoint {
72 line,
73 column,
74 condition,
75 hit_condition,
76 log_message,
77 } = args;
78
79 let line = utils::attribute_u64("line", line);
80 let column = utils::attribute_u64_optional("column", column);
81 let condition = utils::attribute_string_optional("condition", condition);
82 let hit_condition = utils::attribute_string_optional("hitCondition", hit_condition);
83 let log_message = utils::attribute_string_optional("logMessage", log_message);
84
85 utils::finalize_object(
86 line.chain(column)
87 .chain(condition)
88 .chain(hit_condition)
89 .chain(log_message),
90 )
91 }
92}
93
94impl TryFrom<&Map<String, Value>> for SourceBreakpoint {
95 type Error = Error;
96
97 fn try_from(map: &Map<String, Value>) -> Result<Self, Self::Error> {
98 let line = utils::get_u64(map, "line")?;
99 let column = utils::get_u64_optional(map, "column")?;
100 let condition = utils::get_string_optional(map, "condition")?;
101 let hit_condition = utils::get_string_optional(map, "hitCondition")?;
102 let log_message = utils::get_string_optional(map, "logMessage")?;
103
104 Ok(Self {
105 line,
106 column,
107 condition,
108 hit_condition,
109 log_message,
110 })
111 }
112}
113
114impl From<SetBreakpointsResponse> for Value {
115 fn from(args: SetBreakpointsResponse) -> Self {
116 let SetBreakpointsResponse { breakpoints } = args;
117
118 let breakpoints = utils::attribute_array("breakpoints", breakpoints);
119
120 utils::finalize_object(breakpoints)
121 }
122}
123
124impl TryFrom<&Map<String, Value>> for SetBreakpointsResponse {
125 type Error = Error;
126
127 fn try_from(map: &Map<String, Value>) -> Result<Self, Self::Error> {
128 let breakpoints = utils::get_array_optional(map, "breakpoints")?;
129
130 Ok(Self { breakpoints })
131 }
132}