Skip to content

Commit

Permalink
Renamed "Interface" to "Channel" and replaced demonstatory "BytesRead…
Browse files Browse the repository at this point in the history
…er" with just comments
  • Loading branch information
george-cosma committed Jan 10, 2024
1 parent baafd01 commit c44f626
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 54 deletions.
15 changes: 8 additions & 7 deletions src/interfaces.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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),
}
3 changes: 1 addition & 2 deletions src/interfaces/jlink.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod board_interface;
pub mod bytes_reader;

pub struct JLinkInterface {}
pub struct JLinkChannel {}
6 changes: 3 additions & 3 deletions src/interfaces/jlink/board_interface.rs
Original file line number Diff line number Diff line change
@@ -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!()
}
Expand Down
9 changes: 0 additions & 9 deletions src/interfaces/jlink/bytes_reader.rs

This file was deleted.

3 changes: 1 addition & 2 deletions src/interfaces/openocd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod board_interface;
pub mod bytes_reader;

pub struct OpenOCDInterface {}
pub struct OpenOCDChannel {}
6 changes: 3 additions & 3 deletions src/interfaces/openocd/board_interface.rs
Original file line number Diff line number Diff line change
@@ -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!()
}
Expand Down
9 changes: 0 additions & 9 deletions src/interfaces/openocd/bytes_reader.rs

This file was deleted.

3 changes: 1 addition & 2 deletions src/interfaces/serial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod board_interface;
pub mod bytes_reader;

pub struct SerialInterface {}
pub struct SerialChannel {}
6 changes: 3 additions & 3 deletions src/interfaces/serial/board_interface.rs
Original file line number Diff line number Diff line change
@@ -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!()
}
Expand Down
9 changes: 0 additions & 9 deletions src/interfaces/serial/bytes_reader.rs

This file was deleted.

7 changes: 2 additions & 5 deletions src/interfaces/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>, TockloaderError>;
}
// Other traits go in here

0 comments on commit c44f626

Please sign in to comment.