diff options
| author | Nathan Lee <me@nwlee.tech> | 2026-06-10 22:27:34 -0500 |
|---|---|---|
| committer | Nathan Lee <me@nwlee.tech> | 2026-06-10 22:27:34 -0500 |
| commit | 0f4993d181bb4dd09a8f2613dd82f267b355fe7e (patch) | |
| tree | b213a68dd99c73360133e7c3d8ded4b87ed3a6b0 /src/mem.rs | |
| parent | f94c087120bf2a241dda51d6311c565dd03b96be (diff) | |
chore: lint
Diffstat (limited to 'src/mem.rs')
| -rw-r--r-- | src/mem.rs | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -19,7 +19,7 @@ impl Memory { virtual_addr: usize::MAX, real_addr: i * PAGE_SIZE, permission: 0, - allocated: 0 + allocated: 0, } } Memory { @@ -43,7 +43,10 @@ impl Memory { pub fn lookup_page(&mut self, virtual_addr: usize, permission: usize) -> Option<usize> { for (i, page) in self.pages.iter().enumerate() { - if page.virtual_addr == virtual_addr && permission >= page.permission && page.allocated == 1 { + if page.virtual_addr == virtual_addr + && permission >= page.permission + && page.allocated == 1 + { return Some(i); } } @@ -52,7 +55,10 @@ impl Memory { pub fn ro_lookup(&self, virtual_addr: usize, permission: usize) -> Option<usize> { for (i, page) in self.pages.iter().enumerate() { - if page.virtual_addr == virtual_addr && page.permission == permission && page.allocated == 1 { + if page.virtual_addr == virtual_addr + && page.permission == permission + && page.allocated == 1 + { return Some(i); } } @@ -81,10 +87,15 @@ impl Memory { Err(()) } } - - pub fn read_multiple_bytes(&self, address: usize, size: usize, permission: usize) -> Result<Box<[u8]>, ()> { + + pub fn read_multiple_bytes( + &self, + address: usize, + size: usize, + permission: usize, + ) -> Result<Box<[u8]>, ()> { let mut ret = []; - for addr in address..address+size { + for addr in address..address + size { if let Ok(byte) = self.read(addr, permission) { ret[addr - address] = byte; } else { @@ -93,13 +104,18 @@ impl Memory { } Ok(Box::new(ret)) } - - pub fn write_multiple_bytes(&mut self, address: usize, bytes: &[u8], permission: usize) -> Result<(), ()> { + + pub fn write_multiple_bytes( + &mut self, + address: usize, + bytes: &[u8], + permission: usize, + ) -> Result<(), ()> { for addr in address..address + bytes.len() { if let Err(_) = self.write(addr, permission, bytes[addr - address]) { return Err(()); - } + } } Ok(()) } -}
\ No newline at end of file +} |
