momentohq / client-sdk-rust

Official Rust SDK for Momento Serverless Cache
Apache License 2.0
12 stars 4 forks source link

fix: storage get response should use Found and NotFound cases #376

Closed anitarua closed 4 months ago

anitarua commented 4 months ago

Closes https://github.com/momentohq/dev-eco-issue-tracker/issues/936

Based on written notes, I think this is the only remaining storage client change in the Rust SDK.

This PR replaces struct GetResponse with enum GetResponse with cases Found (contains a StorageValue) and NotFound (no StorageValue).

// quick conversion
let resp = storage_client.get(store_name, key).await?;
let found_value: String = resp.try_into()?;

// full switch statement
match storage_client.get(store_name, key).await? {
  GetResponse::Found { value } => {
    let found_value: f64 = value.try_into()?;
    // wrong type try_into shows "Error: MomentoError { message: "item is not an f64", error_code: TypeError, inner_error: None, details: None }"
  }
  GetResponse::NotFound => println!("Key {key} not found in {store_name}"),
}
anitarua commented 4 months ago

Yeah, not found error indicates item not found