1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use interface::*;
use errors::*;
pub struct ReadOnly<M: MemoryBlock> {
mem: Box<M>,
}
impl<M: MemoryBlock> MemoryMiddlewareCreator<M> for ReadOnly<M> {
fn new(mem: Box<M>) -> Self {
ReadOnly {
mem: mem
}
}
}
impl<M: MemoryBlock> MemoryBlock for ReadOnly<M> {
fn get_size(&self) -> Addr {
self.mem.get_size()
}
fn get(&self, addr: Addr) -> Result<Byte, Error> {
self.mem.get(addr)
}
fn set(&mut self, addr: Addr, _: Byte) -> Result<(), Error> {
bail!(ErrorKind::ReadOnly(addr, true))
}
}