moros 0.6.0

MOROS: Obscure Rust Operating System
Documentation
diff --git a/Cargo.lock b/Cargo.lock
index c01bab3..00a939d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -127,6 +127,18 @@ dependencies = [
  "generic-array",
 ]
 
+[[package]]
+name = "enum_dispatch"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bd53b3fde38a39a06b2e66dc282f3e86191e53bd04cc499929c15742beae3df8"
+dependencies = [
+ "once_cell",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "float-cmp"
 version = "0.9.0"
@@ -220,6 +232,7 @@ dependencies = [
  "base64",
  "bit_field 0.10.1",
  "bootloader",
+ "enum_dispatch",
  "float-cmp",
  "hmac",
  "lazy_static",
@@ -250,6 +263,12 @@ dependencies = [
  "autocfg",
 ]
 
+[[package]]
+name = "once_cell"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
+
 [[package]]
 name = "opaque-debug"
 version = "0.3.0"
diff --git a/Cargo.toml b/Cargo.toml
index 0642f8b..680d16c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -43,6 +43,7 @@ time = { version = "0.2.27", default-features = false }
 uart_16550 = "0.2.15"
 vte = "0.10.1"
 x86_64 = "0.14.4"
+enum_dispatch = "0.3.7"
 
 [package.metadata.bootimage]
 test-success-exit-code = 33 # (0x10 << 1) | 1
diff --git a/src/sys/net/mod.rs b/src/sys/net/mod.rs
index e4dfe11..597e268 100644
--- a/src/sys/net/mod.rs
+++ b/src/sys/net/mod.rs
@@ -1,34 +1,37 @@
+pub mod rtl8139;
+pub mod pcnet;
+
+use rtl8139::RTL8139;
+use pcnet::PCNET;
+
 use alloc::sync::Arc;
 use core::sync::atomic::{AtomicU64, Ordering};
 use lazy_static::lazy_static;
 use spin::Mutex;
 
-// TODO: Support dyn EthernetInterface
-pub type EthernetInterface<T> = smoltcp::iface::EthernetInterface<'static, T>;
-
-#[cfg(feature = "rtl8139")]
-pub mod rtl8139;
+use smoltcp::socket::SocketSet;
+use smoltcp::time::Instant;
+use core::time::Duration;
+use smoltcp::Result;
 
-#[cfg(feature = "rtl8139")]
 lazy_static! {
-    pub static ref IFACE: Mutex<Option<EthernetInterface<rtl8139::RTL8139>>> = Mutex::new(None);
+    pub static ref IFACE: Mutex<Option<EthernetInterface>> = Mutex::new(None);
 }
 
-#[cfg(feature = "rtl8139")]
-pub fn init() {
-    rtl8139::init();
+#[enum_dispatch]
+pub enum EthernetInterface {
+    RTL8139,
+    PCNET,
 }
 
-#[cfg(feature = "pcnet")]
-pub mod pcnet;
-
-#[cfg(feature = "pcnet")]
-lazy_static! {
-    pub static ref IFACE: Mutex<Option<EthernetInterface<pcnet::PCNET>>> = Mutex::new(None);
+#[enum_dispatch(EthernetInterface)]
+trait EthernetInterface {
+    pub fn poll(&mut self, sockets: &mut SocketSet<'_>,timestamp: Instant) -> Result<bool>;
+    pub fn poll_delay(&self, sockets: &SocketSet<'_>, timestamp: Instant) -> Option<Duration>;
 }
 
-#[cfg(feature = "pcnet")]
 pub fn init() {
+    rtl8139::init();
     pcnet::init();
 }
 
diff --git a/src/sys/net/pcnet.rs b/src/sys/net/pcnet.rs
index 587128a..0e5104d 100644
--- a/src/sys/net/pcnet.rs
+++ b/src/sys/net/pcnet.rs
@@ -1,6 +1,7 @@
 use crate::{sys, usr};
 use crate::sys::allocator::PhysBuf;
 use crate::sys::net::Stats;
+use crate::sys::net::EthernetInterface;
 
 use alloc::collections::BTreeMap;
 use alloc::sync::Arc;
@@ -456,7 +457,7 @@ pub fn init() {
                 routes(routes).
                 finalize();
 
-            *sys::net::IFACE.lock() = Some(iface);
+            *sys::net::IFACE.lock() = Some(EthernetInterface::PCNET(iface));
         }
     }
 }
diff --git a/src/sys/net/rtl8139.rs b/src/sys/net/rtl8139.rs
index 174e329..4eed684 100644
--- a/src/sys/net/rtl8139.rs
+++ b/src/sys/net/rtl8139.rs
@@ -1,6 +1,8 @@
 use crate::{sys, usr};
 use crate::sys::allocator::PhysBuf;
 use crate::sys::net::Stats;
+use crate::sys::net::EthernetInterface;
+
 use alloc::collections::BTreeMap;
 use alloc::vec::Vec;
 use array_macro::array;
@@ -382,7 +384,7 @@ pub fn init() {
                 routes(routes).
                 finalize();
 
-            *sys::net::IFACE.lock() = Some(iface);
+            *sys::net::IFACE.lock() = Some(EthernetInterface::RTL8139(iface));
         }
 
         //let irq = pci_device.interrupt_line;