diff --git a/backend-rust/step2-database-only/src/database.rs b/backend-rust/step2-database-only/src/database.rs index b7414b4..d220db4 100644 --- a/backend-rust/step2-database-only/src/database.rs +++ b/backend-rust/step2-database-only/src/database.rs @@ -5,15 +5,11 @@ pub fn query(bytes: &str) -> AppResult { let response = sqlite::call(bytes.as_bytes()); // Decode query result to a utf8 string - match String::from_utf8(response) { - Ok(string) => Ok(string), - Err(err) => { - log::error!("unable to decode result from bytes: {:#x?}", bytes); - Err(err_msg(&format!( - "unable to decode result from bytes {:#x?}: {}", - bytes, err - ))) - } - } - + String::from_utf8(response).map_err(|e| { + log::error!("unable to decode result from bytes: {:#x?}", bytes); + err_msg(&format!( + "unable to decode result from bytes {:#x?}: {}", + bytes, e + )) + }) } diff --git a/backend-rust/step3-finished-app/src/database.rs b/backend-rust/step3-finished-app/src/database.rs index b7414b4..d220db4 100644 --- a/backend-rust/step3-finished-app/src/database.rs +++ b/backend-rust/step3-finished-app/src/database.rs @@ -5,15 +5,11 @@ pub fn query(bytes: &str) -> AppResult { let response = sqlite::call(bytes.as_bytes()); // Decode query result to a utf8 string - match String::from_utf8(response) { - Ok(string) => Ok(string), - Err(err) => { - log::error!("unable to decode result from bytes: {:#x?}", bytes); - Err(err_msg(&format!( - "unable to decode result from bytes {:#x?}: {}", - bytes, err - ))) - } - } - + String::from_utf8(response).map_err(|e| { + log::error!("unable to decode result from bytes: {:#x?}", bytes); + err_msg(&format!( + "unable to decode result from bytes {:#x?}: {}", + bytes, e + )) + }) }