Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I want to return a value in this function as efficiently as possible
- //If possible with no allocations to the heap
- fn sum_all_items() -> Result<usize, &'static str> {
- if let Ok(item) = load_all_items().map(|user| user.iter().count()) {
- // Get all items in a db using the `load_all_items() function` which returns a `Result<Vec<Items>, Err>
- //Use a `map` to extract the value
- //Use `.iter().count()` on the value to count all items of the Vec
- //Here a usize is returned from calculating
- Ok(item)
- }else {
- //In case of an error, the values returned is a string
- Err("DB_READ_ERROR")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement