Skip to content

Commit

Permalink
Modified to use an associated type for Instant (#3)
Browse files Browse the repository at this point in the history
* Modified to use an associated type for Instant

* Modified emulator-hal-memory to match
  • Loading branch information
transistorfet authored Mar 23, 2024
1 parent 1000066 commit 2391a32
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 76 deletions.
14 changes: 9 additions & 5 deletions emulator-hal-memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use alloc::vec::Vec;
use core::marker::PhantomData;

use emulator_hal::bus::{BusAccess, SimpleBusError};
use emulator_hal::time;

/// A contiguous block of memory, backed by a `Vec`
pub struct MemoryBlock<Address, Instant>
Expand Down Expand Up @@ -75,10 +76,12 @@ where
*/
}

impl<Address, Instant> BusAccess<Address, Instant> for MemoryBlock<Address, Instant>
impl<Address, Instant> BusAccess<Address> for MemoryBlock<Address, Instant>
where
Address: TryInto<usize> + Copy,
Instant: time::Instant,
{
type Instant = Instant;
type Error = SimpleBusError;

fn read(
Expand Down Expand Up @@ -111,7 +114,8 @@ where
mod tests {
use super::*;
use alloc::vec;
use std::time::Instant;
use emulator_hal::time::Instant;
use std::time::Duration;

#[test]
fn test_memory_block() {
Expand All @@ -124,11 +128,11 @@ mod tests {
}
}

let mut memory = MemoryBlock::<u64, Instant>::from(vec![0; 1024]);
let mut memory = MemoryBlock::<u64, Duration>::from(vec![0; 1024]);

let number = 0x1234_5678;
memory.write_leu32(Instant::now(), 0, number).unwrap();
let result = memory.read_leu32(Instant::now(), 0).unwrap();
memory.write_leu32(Duration::START, 0, number).unwrap();
let result = memory.read_leu32(Duration::START, 0).unwrap();
assert_eq!(result, number);
}
}
Loading

0 comments on commit 2391a32

Please sign in to comment.