• 0 Posts
  • 23 Comments
Joined 1 year ago
cake
Cake day: June 21st, 2023

help-circle

  • You can’t create a subset of an enum directly, but splitting this up into multiple types works. You can have FunctionAError with errors that function can produce and a variant for your common errors, and FunctionBError which is similar:

    #[derive(Debug, Error)]
    enum MyErrorCommon {
        #[error("bad value ({0})")]
        MyErrorCommon(String),
    }
    
    #[derive(Debug, Error)]
    enum FunctionAError {
        #[error("error a")]
        MyErrorA,
        Common(#[from] MyErrorCommon),
    }
    
    // and same for FunctionBError
    

    The try operator (?) will automatically use From impls to convert errors for you as well. If a function returns a result containing MyErrorCommon in your function and you use ? on it, it gets converted to that function’s error type for you. thiserror generates the From impl for you if you use #[from].



















  • I made the mistake of starting Frostpunk (1) since I saw that 2 released. It’s an incredibly well-made game. The art style is beautiful, the game is intense, there is a lot of emotion, and it does its one thing just so well. Unlike a lot of modern games these days, Frostpunk wants you to lose, which is fitting for its setting. It sees that you’re behind, then kicks you in the shins for good measure rather than lending a helping hand. I’ve lost so many hours of my time to this game in the past week.

    I’ve read that Frostpunk 2 is a completely different game. That one might be next on my list if I get to it before Factorio updates and the expansion for it comes out.