From dec083d858d2ce80f4abab74928ed3904148ffce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Tue, 23 Jul 2024 10:48:59 +0100
Subject: [PATCH] chore: more trait implementations

---
 src/cheats/mod.rs      |  5 +++++
 src/devices/printer.rs | 12 ++++++++++++
 src/gb.rs              | 18 ++++++++++++++++++
 src/pad.rs             |  6 ++++++
 src/serial.rs          |  2 ++
 src/state.rs           |  6 ++++++
 6 files changed, 49 insertions(+)

diff --git a/src/cheats/mod.rs b/src/cheats/mod.rs
index 04bb0032..411161d7 100644
--- a/src/cheats/mod.rs
+++ b/src/cheats/mod.rs
@@ -1,2 +1,7 @@
+//! Implementation of the cheating support for the Game Boy.
+//!
+//! Supports both [Game Genie](https://en.wikipedia.org/wiki/Game_Genie)
+//! and [GameShark](https://en.wikipedia.org/wiki/GameShark) systems.
+
 pub mod genie;
 pub mod shark;
diff --git a/src/devices/printer.rs b/src/devices/printer.rs
index dade2045..bdfe76f5 100644
--- a/src/devices/printer.rs
+++ b/src/devices/printer.rs
@@ -67,6 +67,12 @@ impl Display for PrinterState {
     }
 }
 
+impl From<u8> for PrinterState {
+    fn from(value: u8) -> Self {
+        Self::from_u8(value)
+    }
+}
+
 #[derive(Clone, Copy, PartialEq, Eq)]
 enum PrinterCommand {
     Init = 0x01,
@@ -104,6 +110,12 @@ impl Display for PrinterCommand {
     }
 }
 
+impl From<u8> for PrinterCommand {
+    fn from(value: u8) -> Self {
+        Self::from_u8(value)
+    }
+}
+
 pub struct PrinterDevice {
     state: PrinterState,
     command: PrinterCommand,
diff --git a/src/gb.rs b/src/gb.rs
index d9b512bf..af8e2348 100644
--- a/src/gb.rs
+++ b/src/gb.rs
@@ -110,6 +110,18 @@ impl Display for GameBoyMode {
     }
 }
 
+impl From<u8> for GameBoyMode {
+    fn from(value: u8) -> Self {
+        Self::from_u8(value)
+    }
+}
+
+impl From<&str> for GameBoyMode {
+    fn from(value: &str) -> Self {
+        Self::from_string(value)
+    }
+}
+
 #[cfg_attr(feature = "wasm", wasm_bindgen)]
 #[derive(Clone, Copy, PartialEq, Eq)]
 pub enum GameBoySpeed {
@@ -154,6 +166,12 @@ impl Display for GameBoySpeed {
     }
 }
 
+impl From<u8> for GameBoySpeed {
+    fn from(value: u8) -> Self {
+        Self::from_u8(value)
+    }
+}
+
 #[cfg_attr(feature = "wasm", wasm_bindgen)]
 #[derive(Clone, Copy, PartialEq, Eq)]
 pub struct GameBoyConfig {
diff --git a/src/pad.rs b/src/pad.rs
index 37cb34fc..aba8acc1 100644
--- a/src/pad.rs
+++ b/src/pad.rs
@@ -40,6 +40,12 @@ impl PadKey {
     }
 }
 
+impl From<u8> for PadKey {
+    fn from(value: u8) -> Self {
+        Self::from_u8(value)
+    }
+}
+
 pub struct Pad {
     down: bool,
     up: bool,
diff --git a/src/serial.rs b/src/serial.rs
index 786e63ad..8e0b1ff6 100644
--- a/src/serial.rs
+++ b/src/serial.rs
@@ -1,3 +1,5 @@
+//! Serial transfer (Link Cable) functions and structures.
+
 use crate::{mmu::BusComponent, warnln};
 
 pub trait SerialDevice {
diff --git a/src/state.rs b/src/state.rs
index 8f281a68..09d93ecc 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -61,6 +61,12 @@ impl BosBlockKind {
     }
 }
 
+impl From<u8> for BosBlockKind {
+    fn from(value: u8) -> Self {
+        Self::from_u8(value)
+    }
+}
+
 pub trait Serialize {
     /// Writes the data from the internal structure into the
     /// provided buffer.
-- 
GitLab