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

help-circle



  • But you’re also missing one use of the impl keyword: fn func() -> impl Trait.

    […] So dropping the impl in [return position] might not be completely impossible like the other uses of impl.

    But the impl markes that it is a trait to the programmers.
    Take the following functions:

    func1()->A{...}
    func2()->A{...}
    

    Does the following snippet compile?

    let mut thing = func1();
    thing = func2();
    

    Under the current rules we know it will. But if A could be a trait, the functions could return different types. We currently mark that with the impl.


    Why? What value does -> () provide? Why not elide that?

    What value is provided by keeping it?

    What value does cluttering up your code with -> () provide?

    Why a syntactic special-case for exactly that type and not any other random type?

    Because the unit type is special, just like the never ! type. () also has the special importance of being the return value of an empty statement and some other stuff.


    languages w/o [semicolons] feel awkward since you’re generally limited to one statement per line

    Then fixing that might make sense. :-)

    It’s fixed with semicolons ;-)








  • You could save 0.64 bit per char more if you actually treated you output as a binary number (using 6 bits per char) and didn’t go through the intermediary string (implicitly using base 100 at 6.64 bits per char).
    This would also make your life easier by allowing bit manipulation to slice/move parts and reducing work for the processor because base 100 means integer divisions, and base 64 means bit shifts. If you want to go down the road of a “complicated” base use base 38 and get similar drawbacks as now, except only 5.25 bits per char.