From d0f513b49c1d876e59e2556813071142c900d254 Mon Sep 17 00:00:00 2001 From: SpontanCombust <61706594+SpontanCombust@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:47:07 +0200 Subject: [PATCH] Added optional serde dependency --- Cargo.lock | 21 +++++++++++++++++++++ crates/net/Cargo.toml | 1 + crates/net/src/messages/common.rs | 3 +++ crates/net/src/messages/notifications.rs | 4 ++++ crates/net/src/messages/requests.rs | 13 +++++++++++++ 5 files changed, 42 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b006cd0..ffe78ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -381,6 +381,7 @@ name = "rw3d_net" version = "0.6.0" dependencies = [ "anyhow", + "serde", "shrinkwraprs", "strum", "strum_macros", @@ -409,6 +410,26 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "serde" +version = "1.0.204" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.204" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "shrinkwraprs" version = "0.3.0" diff --git a/crates/net/Cargo.toml b/crates/net/Cargo.toml index 756c809..42bc995 100644 --- a/crates/net/Cargo.toml +++ b/crates/net/Cargo.toml @@ -6,6 +6,7 @@ edition.workspace = true authors.workspace = true [dependencies] +serde = { version = "1.0", features = ["derive"], optional = true } anyhow.workspace = true shrinkwraprs.workspace = true strum.workspace = true diff --git a/crates/net/src/messages/common.rs b/crates/net/src/messages/common.rs index 2459554..3e89935 100644 --- a/crates/net/src/messages/common.rs +++ b/crates/net/src/messages/common.rs @@ -1,9 +1,12 @@ use strum_macros::{AsRefStr, EnumString}; +#[cfg(feature = "serde")] +use serde::{Serialize, Deserialize}; use crate::protocol::*; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, AsRefStr, EnumString)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum WitcherNamespace { #[strum(serialize = "ScriptDebugger")] ScriptDebugger, diff --git a/crates/net/src/messages/notifications.rs b/crates/net/src/messages/notifications.rs index 03f0f73..24492a4 100644 --- a/crates/net/src/messages/notifications.rs +++ b/crates/net/src/messages/notifications.rs @@ -1,6 +1,8 @@ use std::path::PathBuf; use anyhow::{bail, Context}; +#[cfg(feature = "serde")] +use serde::{Serialize, Deserialize}; use crate::protocol::*; use super::{Message, WitcherNamespace}; @@ -38,6 +40,7 @@ impl DisassemblePayload for ListenToNamespaceId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ListenToNamespaceParams { pub namesp: WitcherNamespace } @@ -122,6 +125,7 @@ impl DisassemblePayload for ScriptsReloadProgressId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum ScriptsReloadProgressParams { Started, Log { diff --git a/crates/net/src/messages/requests.rs b/crates/net/src/messages/requests.rs index c0cec58..6e02432 100644 --- a/crates/net/src/messages/requests.rs +++ b/crates/net/src/messages/requests.rs @@ -1,6 +1,8 @@ use std::path::PathBuf; use anyhow::Context; +#[cfg(feature = "serde")] +use serde::{Serialize, Deserialize}; use crate::protocol::*; use super::{Message, WitcherNamespace}; @@ -77,6 +79,7 @@ impl DisassemblePayload for ScriptsRootPathResponseId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ScriptsRootPathResult { pub abs_path: PathBuf } @@ -139,6 +142,7 @@ impl DisassemblePayload for ExecuteCommandId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ExecuteCommandParams { pub cmd: String } @@ -194,6 +198,7 @@ impl DisassemblePayload for ExecuteCommandResponseId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum ExecuteCommandResult { Success { log_output: Option> @@ -322,11 +327,13 @@ impl DisassemblePayload for ScriptPackagesResponseId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ScriptPackagesResult { pub packages: Vec } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ScriptPackageInfo { pub package_name: String, pub abs_scripts_root_path: PathBuf @@ -403,6 +410,7 @@ impl DisassemblePayload for OpcodesId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct OpcodesParams { pub func_name: String, pub class_name: Option, @@ -473,11 +481,13 @@ impl DisassemblePayload for OpcodesResponseId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct OpcodesResult { pub breakdowns: Vec } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct OpcodeBreakdown { pub line: i32, pub opcodes: Vec @@ -568,6 +578,7 @@ impl DisassemblePayload for ConfigVarsId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ConfigVarsParams { pub section_filter: Option, pub name_filter: Option @@ -630,11 +641,13 @@ impl DisassemblePayload for ConfigVarsResponseId { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ConfigVarsResult { pub vars: Vec } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct ConfigVarInfo { pub section: String, pub name: String,