Make VRRPv2Error std::error::Error trait compliant. default tip
authorSunil Nimmagadda <sunil@nimmagadda.net>
Sun, 26 May 2024 13:19:51 +0530
changeset 29 277a2f8b3653
parent 28 31219e9f8a9e
Make VRRPv2Error std::error::Error trait compliant.
src/vrrpv2.rs
--- a/src/vrrpv2.rs	Tue Apr 23 20:08:02 2024 +0530
+++ b/src/vrrpv2.rs	Sun May 26 13:19:51 2024 +0530
@@ -1,3 +1,4 @@
+use std::fmt::Display;
 use std::io::Read;
 use std::io::{self, Cursor};
 use std::net::Ipv4Addr;
@@ -44,6 +45,18 @@
     ParseError,
 }
 
+impl Display for VRRPv2Error {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            Self::InvalidAuthType => write!(f, "Invalid Auth Type"),
+            Self::InvalidChecksum => write!(f, "Invalid Checksum"),
+            Self::InvalidType => write!(f, "Invalid Type"),
+            Self::InvalidVersion => write!(f, "Invalid Version"),
+            Self::ParseError => write!(f, "Parse Error"),
+        }
+    }
+}
+
 #[derive(Debug, PartialEq)]
 pub enum VRRPv2AuthType {
     VRRPv2AuthNoAuth = 0x00,