Skip to content

Commit

Permalink
Added enum dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
george-cosma committed Aug 20, 2023
1 parent 9999491 commit 40c9c63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2021"

[dependencies]
clap = { version = "4.1.1", features = ["cargo"] }
enum_dispatch = "0.3.12"
14 changes: 14 additions & 0 deletions src/interfaces.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
use self::{
board_interface::BoardInterface, jlink::JLinkInterface, openocd::OpenOCDInterface,
serial::SerialInterface,
};
use crate::errors::TockloaderError;
use enum_dispatch::enum_dispatch;

pub mod board_interface;
pub mod jlink;
pub mod openocd;
pub mod serial;

#[enum_dispatch(BoardInterface)]
pub enum Interface {
Serial(SerialInterface),
OpenOCD(OpenOCDInterface),
JLink(JLinkInterface),
}
3 changes: 3 additions & 0 deletions src/interfaces/board_interface.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::errors::TockloaderError;

use enum_dispatch::enum_dispatch;

#[enum_dispatch]
pub trait BoardInterface {
fn open(&mut self) -> Result<(), TockloaderError>;
}

0 comments on commit 40c9c63

Please sign in to comment.