• 0 Posts
  • 10 Comments
Joined 1 year ago
cake
Cake day: July 10th, 2023

help-circle

  • jameseb@lemm.eetoRust@programming.devRust Container Cheat Sheet
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    6 months ago
    1. Why does it say where T: Sized for references &T? A reference can definitely point to an unsized type, e.g. &str.

    I think the point being made is that the layout shown only applies for Sized T. Layouts for &[T] and &dyn Trait are shown elsewhere on the sheet. &str is noted under &[T].

    Edit: although, similar considerations would apply to other pointer types, but that isn’t noted on the sheet except for Box<[T]>




  • A few things I noticed:

    • In http::request::parse(), do you actually need a BufReader? It would be better to make it generic over something implementing BufRead, that allows what you have but also makes tests and examples easier since you wouldn’t have to open a TCP connection just to do something that is essentially string parsing.
    • In http::response::Response::to_string(), that match on lines 78-85 makes me uneasy, because you are silently changing the status code if it isn’t one you recognise. It would be better to signal an error. It would be even better to just check when the status code is set (perhaps with a status code enum to list the ones you support, since what you have isn’t all the defined codes) so that you can’t fail when converting to a string.
    • Consider whether you need a special to_string() method at all, or whether you can just implement Display (which gives you to_string() for free via the ToString trait).
    • You are using String as an error type pretty much everywhere. The better approach is to create an enum representing all the possible errors, so that a user of your library can match against them. Make the enum implement Error and Display and it will fit fine into the rest of the error handling infrastructure. There are crates like thiserror that can reduce the boilerplate around this.
    • You have an io.rs that doesn’t appear to be connected to anything.
    • You have a main.rs, which seems off in something that sounds like it should be purely a library crate. You probably want that to be an example or an integration test instead.

    That’s all I could see with a quick look. In terms of general advice: remember to look at warnings, run cargo clippy, and look at the API guidelines.


  • 25 isn’t too young, and makes sense if you have focused on education and career. I followed a similar path in that I spent a lot of time in education, only starting to properly consider courting someone around the age of 25 or 26 after I finished my PhD. Things were complicated somewhat by Covid, but I got married last year at the age of 30.

    As to losing weight, I can’t speak much from experience on that, but losing some weight may be a good idea, as much for your own health as anything else. Unless you are really overweight (in which case it is a medical issue that you should address), I think you shouldn’t worry too much about it in terms of dating.