From 552020e9c1baa47ab7480e662a4950935cb8b393 Mon Sep 17 00:00:00 2001 From: Rafal Michalski Date: Sun, 25 Feb 2024 19:53:55 +0100 Subject: [PATCH] examples: ral1243 - fix Memory::free_exrom_slots to not underreport the count, change Memory::attach_exroms to return a count --- examples/ral1243/src/memory.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/ral1243/src/memory.rs b/examples/ral1243/src/memory.rs index f412b1d..1727f36 100644 --- a/examples/ral1243/src/memory.rs +++ b/examples/ral1243/src/memory.rs @@ -78,12 +78,11 @@ impl Memory { } /// Return a number of `EX-ROM` slots that can still be populated. pub fn free_exrom_slots(&self) -> usize { - u8::max_value() as usize - self.exroms.len() + (u8::max_value() as usize + 1) - self.exroms.len() } /// Attach `EX-ROMS` from the given `exroms` collection. - /// - /// **Panics** if there is no more room for `exroms`. - pub fn attach_exroms(&mut self, exroms: I) + /// Return the number of inserted `EX-ROMS`. + pub fn attach_exroms(&mut self, exroms: I) -> usize where I: IntoIterator, I::IntoIter: ExactSizeIterator { @@ -92,6 +91,7 @@ impl Memory { for exrom in exroms.take(max_exroms) { self.attach_exrom(exrom); } + max_exroms } /// Attach a given `EX-ROM`. Return a total number of inserted `EX-ROMS`. ///