on master help sign in
refactor: use tagged enum for handling DAP payloads
commit279db98d3cb6c7ee41af81c3e8eb6ef69a1662d0 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 15 Aug 2021, 10:08 (5 years ago) parent36fb8d1
2 files changed+2−9
helix-dap/src/client.rs−1 helix-dap/src/transport.rs+2−8
helix-dap/src/client.rs−1
@@ -461,7 +461,6 @@ impl Client {
461461 let req = Request {
462462 back_ch: Some(callback_rx),
463463 seq: self.next_request_id(),
464− msg_type: "request".to_owned(),
465464 command,
466465 arguments,
467466 };
helix-dap/src/transport.rs+2−8
@@ -18,8 +18,6 @@ pub struct Request {
1818 #[serde(skip)]
1919 pub back_ch: Option<Sender<Result<Response>>>,
2020 pub seq: u64,
21− #[serde(rename = "type")]
22− pub msg_type: String,
2321 pub command: String,
2422 pub arguments: Option<Value>,
2523}
@@ -27,8 +25,6 @@ pub struct Request {
2725#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
2826pub struct Response {
2927 // seq is omitted as unused and is not sent by some implementations
30− #[serde(rename = "type")]
31− pub msg_type: String,
3228 pub request_seq: u64,
3329 pub success: bool,
3430 pub command: String,
@@ -39,14 +35,12 @@ pub struct Response {
3935#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
4036pub struct Event {
4137 // seq is omitted as unused and is not sent by some implementations
42− #[serde(rename = "type")]
43− pub msg_type: String,
4438 pub event: String,
4539 pub body: Option<Value>,
4640}
4741
4842#[derive(Debug, Clone, Deserialize, Serialize)]
49−#[serde(untagged)]
43+#[serde(tag = "type", rename_all = "camelCase")]
5044pub enum Payload {
5145 // type = "event"
5246 Event(Event),
@@ -135,7 +129,7 @@ impl Transport {
135129 server_stdin: &mut Box<dyn AsyncWrite + Unpin + Send>,
136130 req: Request,
137131 ) -> Result<()> {
138− let json = serde_json::to_string(&req)?;
132+ let json = serde_json::to_string(&Payload::Request(req.clone()))?;
139133 if let Some(back) = req.back_ch {
140134 self.pending_requests.lock().await.insert(req.seq, back);
141135 }