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/)J
Posts
0
Comments
237
Joined
2 yr. ago

  • You can do type erasure by converting your errors to Box<dyn Error>, then they have the same type and can be in the same enum variant

  • For multiple types turning into one variant: you can either impl From for the others yourself, or you can have another enum with variants for them and have thiserror generate the From impl. I usually have lots of enums, at least one per module, sometimes even one per function, that form a tree. The errors you design should relate to the action that was being tried, and only encapsulate the lower error as context information.

    I see you're using strings. You can do that, but then you'll lose control over formatting, and additional context info that might be contained in them.

    Designing errors isn't trivial and requires some experience. Try some things and over time you'll see what works best.

    You can also check out https://docs.rs/snafu/latest/snafu/guide/index.html, another great library - their docs contain excellent guidance on designing error types.

  • Don't implement Into, instead, implement From - and you'll get Into for free

  • Check out https://docs.rs/thiserror/latest/thiserror/. You can do this:

     rust
        
    #[derive(Debug, thiserror::Error)]
    pub enum MyError {
        #[error("Failed to do the thing, blabla, put something clear here")]
        DoingTheThing(#[from] LibraryError)
    }
    
      

    And then you can just do foo(a, b)? because there's now a From impl for MyError from LibraryError.

    You now get a proper error chain via source(). You can use this to have a nice report at the top level using https://docs.rs/thiserror-ext/0.3.0/thiserror_ext/struct.Report.html that looks like this:

     
        
    Outer error text
    
    Caused by these errors (recent errors listed first):
      1. Middle error text
      2. Inner error text
    
      

  • They are craving for recognition.

  • The fact that you're even asking this tells me that you're more considerate than most. You'll be fine!

  • Writing stuff in Rust

  • Regex describes a parser.

  • I assume you're asking this because you'd like to reduce the impact of that kind of behaviour.

    If that is your goal, then it would be best attained by going to psychotherapy. NCD/ASPD cannot be healed, but it can be treated and its effects greatly reduced, assuming you're willing to put in the work.

  • Let me put it this way: When I am in a restaurant/bar/pub/similar place, I can't follow the conversations of the people at the other tables. However, with US-Americans, I understand every single word, even if they're two tables over. Their normal conversational volume is just so much higher. To them, it is completely normal, and they don't seem to notice. To us, they're speaking very loudly, as if everyone were hard of hearing, or as if we were on a construction site.

  • There's a not-so-small difference between weird and annoying leftovers in specific areas and going all in with it in everyday life and still teaching it to every child.

  • It is simply the law.

    For example, in Switzerland, no employee may work more than 45 hours per week in the normal case (there are exceptions). Even if the employee and employer agree to ignore this, the employer will get absolutely rekt by the (mandatory) insurance if anything happens to the employee - even an accident in the employee's free time.

    It's not the same, but similar, in other European countries.

  • In Deutschland gibt es eine gesetzliche wöchentliche Höchstarbeitszeit. Ja die kann in Notfällen undso überschritten werden, aber die Leute arbeiten nicht oft 24h am Stück ohne Pause als wäre das etwas völlig normales

  • En France vous avez des lois qui limitent le maximum des heures travaillés par semaine. Oui dans des cas éxtraordinaire c'est possible de les ignorer, mais c'est une grande difference en comparaison avec les états-unis, où ils travaillent pendant 24h sans pause comme c'est une chôse normal

  • No one does this outside of the USA. It is not at all normal, just like being stuck with the imperial system of measurements.

  • Even more so. The slop needs to be checked more thoroughly than human written code, because they are good at generating something that looks reasonable at first glance, but at closer inspection is actually bullshit.

  • Oh, I hadn't noticed. Bad example

  • Maybe they have a small freezer, idk. We have a vegetable subscription from a local farm, it's great. Vegetables get delivered once a week, and they're so fresh we can really taste the difference.