Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)KA
Posts
5
Comments
363
Joined
2 yr. ago

  • Here's some examples written on my phone:

     
        
    match result {
        Ok(bool_name) => whatever,
        Err(error_type) => whatever,
    }
    
    if let Ok(bool_name) = result {
        whatever
    }
    
    if result.is_ok() {
        whatever
    }
    
    let whatever = result.unwrap_or_default();
    let whatever = result?;
    
      

    And there's many other awesome ways to use a Result including turning it into an Option or unwrapping it unsafely. I recommend you just search "Rust book" on your search engine and browse it. Here's the docs to the Result enum.

  • It's a great and probably the best error system I've seen, instead of just throwing errors and having bulky try catch statements and such there's just a result type.

    Say you have a function that returns a boolean in which something could error, the function would return a Result<bool, Error> and that's it. Calling the function you can choose to do anything you want with that possible Error, including ignoring it or logging or anything you could want.

    It's extremely simple.