embedded_shadow/
policy.rs

1pub trait AccessPolicy {
2    fn can_read(&self, addr: u16, len: usize) -> bool;
3    fn can_write(&self, addr: u16, len: usize) -> bool;
4}
5
6#[derive(Default)]
7pub struct AllowAllPolicy {}
8
9impl AccessPolicy for AllowAllPolicy {
10    fn can_read(&self, _addr: u16, _len: usize) -> bool {
11        true
12    }
13
14    fn can_write(&self, _addr: u16, _len: usize) -> bool {
15        true
16    }
17}
18
19pub trait PersistPolicy<PK> {
20    fn push_persist_keys_for_range<F>(&self, addr: u16, len: usize, push_key: F) -> bool
21    where
22        F: FnMut(PK);
23}
24
25#[derive(Default)]
26pub struct NoPersistPolicy {}
27
28impl PersistPolicy<()> for NoPersistPolicy {
29    fn push_persist_keys_for_range<F>(&self, _addr: u16, _len: usize, _push_key: F) -> bool {
30        false
31    }
32}