if you let AI add Deserialize for everything Serialize you will have to fight this

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
lda
2026-05-03 03:58:04 +07:00
co-authored by Copilot
Verified
parent f5ed1ab8f6
commit 64cf5f9e69
7 changed files with 39 additions and 4 deletions
+3
View File
@@ -10,3 +10,6 @@ serde = { workspace = true }
serde_with = { version = "3", features = ["json"] }
strum = { version = "0", features = ["derive", "strum_macros"] }
thiserror = "2"
[dev-dependencies]
serde_json.workspace = true
+25 -1
View File
@@ -12,7 +12,7 @@ use crate::parse::mac;
pub struct NeighborEntry {
pub ip: IpAddr,
pub dev: Option<String>,
#[serde(with = "mac::option_mac")]
#[serde(with = "mac::option_mac", default)]
pub mac: Option<MacAddr>,
pub state: NeighborState,
}
@@ -132,3 +132,27 @@ impl FromStr for NeighborEntry {
parse_neighbor_line(s)
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn deserialize_online_neighbor() {
NeighborEntry::deserialize(serde_json::json!({
"ip" : "192.168.100.94",
"dev" : "br-lan",
"mac" : "04:7C:16:79:6D:EE",
"state" : "REACHABLE"
}))
.expect("all fields must pass");
}
#[test]
fn deserialize_failed_neighbor() {
NeighborEntry::deserialize(serde_json::json!({
"ip" : "192.168.100.94",
"dev" : "br-lan",
"state" : "FAILED"
}))
.expect("default");
}
}