Skip to content

Instantly share code, notes, and snippets.

@DougAnderson444
Created June 27, 2025 16:27
Show Gist options
  • Select an option

  • Save DougAnderson444/04b7dcd6bffa197c0ffaf211d24c7c62 to your computer and use it in GitHub Desktop.

Select an option

Save DougAnderson444/04b7dcd6bffa197c0ffaf211d24c7c62 to your computer and use it in GitHub Desktop.

Revisions

  1. DougAnderson444 created this gist Jun 27, 2025.
    23 changes: 23 additions & 0 deletions map_unwrap.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    🚀 Simplifying your Rust `Result`s! Technically Result is an enum, so you _can_ match on it:

    ```rust
    // Instead of this:
    match some_function(&input) {
    Ok(value) => process_value(value),
    Err(err) => {
    log_error(err);
    }
    }
    ```

    But Result comes with great functional methods built in to streamline your code:
    ```rs
    // Use this:
    some_function(&input)
    .map(|value| process_value(value))
    .unwrap_or_else(|err| {
    log_error(err);
    handle_error();
    });
    ```
    Cleaner, more concise, and still handles errors effectively! 💡 #RustLang #CodingTips #ErrorHandling