Skip to content

Commit 3b4066c

Browse files
committed
dev: expose get_maybe_relocatable instead
1 parent a57696a commit 3b4066c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

vm/src/vm/vm_memory/memory.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl Memory {
238238
}
239239

240240
/// Retrieve a value from memory (either normal or temporary) and apply relocation rules
241-
pub fn get<'a, 'b: 'a, K: 'a>(&'b self, key: &'a K) -> Option<Cow<'b, MaybeRelocatable>>
241+
pub(crate) fn get<'a, 'b: 'a, K: 'a>(&'b self, key: &'a K) -> Option<Cow<'b, MaybeRelocatable>>
242242
where
243243
Relocatable: TryFrom<&'a K>,
244244
{
@@ -448,6 +448,18 @@ impl Memory {
448448
}
449449
}
450450

451+
/// Gets the value from memory address as a MaybeRelocatable value.
452+
/// Returns an Error if the value at the memory address is missing or not a MaybeRelocatable.
453+
pub fn get_maybe_relocatable(&self, key: Relocatable) -> Result<MaybeRelocatable, MemoryError> {
454+
match self
455+
.get(&key)
456+
.ok_or_else(|| MemoryError::UnknownMemoryCell(Box::new(key)))?
457+
{
458+
Cow::Borrowed(maybe_rel) => Ok(maybe_rel.clone()),
459+
Cow::Owned(maybe_rel) => Ok(maybe_rel),
460+
}
461+
}
462+
451463
/// Inserts a value into memory
452464
/// Returns an error if the memory cell asignment is invalid
453465
pub fn insert_value<T: Into<MaybeRelocatable>>(

0 commit comments

Comments
 (0)