@@ -125,26 +125,18 @@ impl Memory {
125125
126126 /// Retrieves and converts the value stored at a given memory address into a desired type `V`.
127127 ///
128+ /// Returns an error if the memory cell is uninitialized or if the conversion fails.
129+ ///
128130 /// # Arguments
129131 /// * `address`: The `MemoryAddress` specifying the location of the cell to retrieve.
130- pub ( crate ) fn get_as < V > ( & self , address : MemoryAddress ) -> Result < Option < V > , MemoryError >
132+ pub ( crate ) fn get_as < V > ( & self , address : MemoryAddress ) -> Result < V , MemoryError >
131133 where
132134 V : TryFrom < MemoryValue , Error = MemoryError > ,
133135 {
134- // Attempt to retrieve the raw memory value at the given address.
135- match self . get ( address) {
136- // If the address is valid and contains a value:
137- Some ( value) => {
138- // Attempt to convert the `MemoryValue` into the desired type `V`.
139- //
140- // If conversion fails, the error will be propagated.
141- let converted = V :: try_from ( value) ?;
142- // Return the successfully converted value wrapped in `Some`.
143- Ok ( Some ( converted) )
144- }
145- // If the address is invalid or the cell is uninitialized, return `None`.
146- None => Ok ( None ) ,
147- }
136+ // Retrieve the raw value and convert it to the desired type `V`.
137+ self . get ( address)
138+ . ok_or ( MemoryError :: UninitializedMemory ( address) )
139+ . and_then ( V :: try_from)
148140 }
149141
150142 /// Retrieves a fixed-size array of field elements starting from a given address.
@@ -201,9 +193,7 @@ impl Memory {
201193 let addr = ( start_address + i) ?;
202194
203195 // Attempt to retrieve the value from the memory and convert it into type `V`.
204- let v = self
205- . get_as ( addr) ?
206- . ok_or ( MemoryError :: UninitializedMemory ( addr) ) ?;
196+ let v = self . get_as ( addr) ?;
207197
208198 // SAFETY: The memory value has been successfully retrieved and converted.
209199 * o = MaybeUninit :: new ( v) ;
0 commit comments