• 0 Posts
  • 35 Comments
Joined 2 years ago
cake
Cake day: July 6th, 2023

help-circle



  • ExitCode is a struct, therefore it behaves like a type with many fields which define the types contained in the struct.

    That’s a bit too off. structs in rust are product types. A struct may define zero or more fields. And fields can be named or not. if not, such structs are called tuple structs.

    In the doc page, if you clicked on source, it would have taken you to the definition.

    pub struct ExitCode(imp::ExitCode);
    

    That’s a public struct with one unnamed private field. The type of the private field also happens to be private/internal.

    As for why, usually the purpose is providing type safety, a unified interface,… etc. Notice how for example a windows-only extension trait is implemented that allows converting raw u32 exit codes into ExitCode.

    So now you have exit codes possibly sourced from u8 or u32 values depending on the platform. And you need a safe unified interface to represent them.

    I hope that’s an enough starting point.


  • I would move all struct members from Foo<false> into a “new” Foo<true> and return that?

    Yes… if you don’t define Drop for Foo.

    If you do, then you will have to either use mem::take()/mem::replace() with each field, or if you don’t mind unsafe {}, you can just do a trivial transmute. Justunsafe { transmute(self) } should work.






  • This is neither news*, nor majorly relevant. Having rustc_codegen_gcc as a rustup component is going to be way more relevant, and is much closer to delivery, just to give an example.

    * The post itself (not the content of it) appearing on the official blog was sort of pleasantly surprising (brought tears to my eyes, i tell ya). Hopefully that was a result of maturity, rather than external pressure.










  • If you’re using an LLM to “learn”, stop. Otherwise, I don’t understand what lazy_static has to do with anything.

    It’s hard to tell what you’re asking. But maybe you’re confused because println! (it’s a macro btw) expands to code that involves format_args! which is a compiler built-in that doesn’t take ownership of the token expressions that get passed to it. Notice how the bottom of the format_args! page has this to say:

    Lifetime limitation

    Except when no formatting arguments are used, the produced fmt::Arguments value borrows temporary values, which means it can only be used within the same expression and cannot be stored for later use. This is a known limitation, see #92698.

    So, it’s kind of a feature and a limitation at the same time.