From c44f626afb9d5d8d140ff992a58f305cb2b5572f Mon Sep 17 00:00:00 2001 From: Cosma George Date: Wed, 10 Jan 2024 09:46:24 +0200 Subject: [PATCH] Renamed "Interface" to "Channel" and replaced demonstatory "BytesReader" with just comments --- src/interfaces.rs | 15 ++++++++------- src/interfaces/jlink.rs | 3 +-- src/interfaces/jlink/board_interface.rs | 6 +++--- src/interfaces/jlink/bytes_reader.rs | 9 --------- src/interfaces/openocd.rs | 3 +-- src/interfaces/openocd/board_interface.rs | 6 +++--- src/interfaces/openocd/bytes_reader.rs | 9 --------- src/interfaces/serial.rs | 3 +-- src/interfaces/serial/board_interface.rs | 6 +++--- src/interfaces/serial/bytes_reader.rs | 9 --------- src/interfaces/traits.rs | 7 ++----- 11 files changed, 22 insertions(+), 54 deletions(-) delete mode 100644 src/interfaces/jlink/bytes_reader.rs delete mode 100644 src/interfaces/openocd/bytes_reader.rs delete mode 100644 src/interfaces/serial/bytes_reader.rs diff --git a/src/interfaces.rs b/src/interfaces.rs index 995c0f4..cb58e84 100644 --- a/src/interfaces.rs +++ b/src/interfaces.rs @@ -1,4 +1,4 @@ -use self::{jlink::JLinkInterface, openocd::OpenOCDInterface, serial::SerialInterface, traits::*}; +use self::{jlink::JLinkChannel, openocd::OpenOCDChannel, serial::SerialChannel, traits::*}; use crate::errors::TockloaderError; use enum_dispatch::enum_dispatch; @@ -7,10 +7,11 @@ pub mod openocd; pub mod serial; pub mod traits; -#[enum_dispatch(BoardInterface)] -#[enum_dispatch(BytesReader)] -pub enum Interface { - Serial(SerialInterface), - OpenOCD(OpenOCDInterface), - JLink(JLinkInterface), +#[enum_dispatch(BoardChannel)] +// To add other traits, just chaing the enum_dispatch directive: +// #[enum_dispatch(AnotherTrait)] +pub enum Channel { + Serial(SerialChannel), + OpenOCD(OpenOCDChannel), + JLink(JLinkChannel), } diff --git a/src/interfaces/jlink.rs b/src/interfaces/jlink.rs index 77361d3..5f95797 100644 --- a/src/interfaces/jlink.rs +++ b/src/interfaces/jlink.rs @@ -1,4 +1,3 @@ pub mod board_interface; -pub mod bytes_reader; -pub struct JLinkInterface {} +pub struct JLinkChannel {} diff --git a/src/interfaces/jlink/board_interface.rs b/src/interfaces/jlink/board_interface.rs index 2444d77..a68ed0c 100644 --- a/src/interfaces/jlink/board_interface.rs +++ b/src/interfaces/jlink/board_interface.rs @@ -1,8 +1,8 @@ use crate::errors::TockloaderError; -use crate::interfaces::traits::BoardInterface; -use crate::interfaces::JLinkInterface; +use crate::interfaces::traits::BoardChannel; +use crate::interfaces::JLinkChannel; -impl BoardInterface for JLinkInterface { +impl BoardChannel for JLinkChannel { fn open(&mut self) -> Result<(), TockloaderError> { todo!() } diff --git a/src/interfaces/jlink/bytes_reader.rs b/src/interfaces/jlink/bytes_reader.rs deleted file mode 100644 index 709c7bb..0000000 --- a/src/interfaces/jlink/bytes_reader.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::errors::TockloaderError; -use crate::interfaces::traits::BytesReader; -use crate::interfaces::JLinkInterface; - -impl BytesReader for JLinkInterface { - fn read_range(&self, _start: usize, _len: usize) -> Result, TockloaderError> { - todo!() - } -} diff --git a/src/interfaces/openocd.rs b/src/interfaces/openocd.rs index 1529ec1..ac81a46 100644 --- a/src/interfaces/openocd.rs +++ b/src/interfaces/openocd.rs @@ -1,4 +1,3 @@ pub mod board_interface; -pub mod bytes_reader; -pub struct OpenOCDInterface {} +pub struct OpenOCDChannel {} diff --git a/src/interfaces/openocd/board_interface.rs b/src/interfaces/openocd/board_interface.rs index 557b3a3..0a70ce9 100644 --- a/src/interfaces/openocd/board_interface.rs +++ b/src/interfaces/openocd/board_interface.rs @@ -1,8 +1,8 @@ use crate::errors::TockloaderError; -use crate::interfaces::traits::BoardInterface; -use crate::interfaces::OpenOCDInterface; +use crate::interfaces::traits::BoardChannel; +use crate::interfaces::OpenOCDChannel; -impl BoardInterface for OpenOCDInterface { +impl BoardChannel for OpenOCDChannel { fn open(&mut self) -> Result<(), TockloaderError> { todo!() } diff --git a/src/interfaces/openocd/bytes_reader.rs b/src/interfaces/openocd/bytes_reader.rs deleted file mode 100644 index 2543a67..0000000 --- a/src/interfaces/openocd/bytes_reader.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::errors::TockloaderError; -use crate::interfaces::traits::BytesReader; -use crate::interfaces::OpenOCDInterface; - -impl BytesReader for OpenOCDInterface { - fn read_range(&self, _start: usize, _len: usize) -> Result, TockloaderError> { - todo!() - } -} diff --git a/src/interfaces/serial.rs b/src/interfaces/serial.rs index 4adaa66..9e40058 100644 --- a/src/interfaces/serial.rs +++ b/src/interfaces/serial.rs @@ -1,4 +1,3 @@ pub mod board_interface; -pub mod bytes_reader; -pub struct SerialInterface {} +pub struct SerialChannel {} diff --git a/src/interfaces/serial/board_interface.rs b/src/interfaces/serial/board_interface.rs index 267a8ef..a8fd627 100644 --- a/src/interfaces/serial/board_interface.rs +++ b/src/interfaces/serial/board_interface.rs @@ -1,8 +1,8 @@ use crate::errors::TockloaderError; -use crate::interfaces::traits::BoardInterface; -use crate::interfaces::SerialInterface; +use crate::interfaces::traits::BoardChannel; +use crate::interfaces::SerialChannel; -impl BoardInterface for SerialInterface { +impl BoardChannel for SerialChannel { fn open(&mut self) -> Result<(), TockloaderError> { todo!() } diff --git a/src/interfaces/serial/bytes_reader.rs b/src/interfaces/serial/bytes_reader.rs deleted file mode 100644 index 279c00e..0000000 --- a/src/interfaces/serial/bytes_reader.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::errors::TockloaderError; -use crate::interfaces::traits::BytesReader; -use crate::interfaces::SerialInterface; - -impl BytesReader for SerialInterface { - fn read_range(&self, _start: usize, _len: usize) -> Result, TockloaderError> { - todo!() - } -} diff --git a/src/interfaces/traits.rs b/src/interfaces/traits.rs index a2f6094..d9b814b 100644 --- a/src/interfaces/traits.rs +++ b/src/interfaces/traits.rs @@ -2,11 +2,8 @@ use crate::errors::TockloaderError; use enum_dispatch::enum_dispatch; #[enum_dispatch] -pub trait BoardInterface { +pub trait BoardChannel { fn open(&mut self) -> Result<(), TockloaderError>; } -#[enum_dispatch] -pub trait BytesReader { - fn read_range(&self, start: usize, len: usize) -> Result, TockloaderError>; -} +// Other traits go in here