embedded_shadow/
policy.rs

1/// Controls read/write access to shadow table regions.
2pub trait AccessPolicy {
3    /// Returns true if reading from `addr` for `len` bytes is allowed.
4    fn can_read(&self, addr: u16, len: usize) -> bool;
5    /// Returns true if writing to `addr` for `len` bytes is allowed.
6    fn can_write(&self, addr: u16, len: usize) -> bool;
7}
8
9/// Default policy that allows all reads and writes.
10#[derive(Default)]
11pub struct AllowAllPolicy {}
12
13impl AccessPolicy for AllowAllPolicy {
14    fn can_read(&self, _addr: u16, _len: usize) -> bool {
15        true
16    }
17
18    fn can_write(&self, _addr: u16, _len: usize) -> bool {
19        true
20    }
21}
22
23/// Determines which regions require persistence and emits keys for them.
24pub trait PersistPolicy<PK> {
25    /// Pushes persistence keys for the given range and returns true if persistence is needed.
26    fn push_persist_keys_for_range<F>(&self, addr: u16, len: usize, push_key: F) -> bool
27    where
28        F: FnMut(PK);
29}
30
31/// Default policy that never triggers persistence.
32#[derive(Default)]
33pub struct NoPersistPolicy {}
34
35impl PersistPolicy<()> for NoPersistPolicy {
36    fn push_persist_keys_for_range<F>(&self, _addr: u16, _len: usize, _push_key: F) -> bool {
37        false
38    }
39}