News for hackers. Stuff that matters.
Re:Optional If Expressions by masklinn on Saturday April 15, 2023 @06:27AM (#35579277)
> There's nothing special about Option, it's not a langitem for example

While Option is not a lang item, Some and None are. Because they are critical to the desugaring of `for` loops for instance.

Thus Option is, transitively, a lang item.

Re:Optional If Expressions by tialaramex on Saturday April 15, 2023 @06:37AM (#35579340)
Good point, I'd forgotten Some and None are indeed needed to de-sugar for. Do you know of anywhere else the actual language guts need them ?
Re:Optional If Expressions by masklinn on Saturday April 15, 2023 @06:57AM (#35579437)
I can't think of an other one, but I won't claim exclusive knowledge of the language's desugaring.
Re:Optional If Expressions by jenadine on Saturday April 15, 2023 @08:16AM (#35579923)
The `?` operator works with Option. I know it is actually through the Try trait internally, but since it is only implemented for a few built-in type, it makes Option special.
Re:Optional If Expressions by masklinn on Saturday April 15, 2023 @08:33AM (#35580055)
Meh. That's just because it's an experimental / unstable trait.

That Rev or Peekable implement TrustedLen does not make them special.

Re:Optional If Expressions by ecton on Saturday April 15, 2023 @09:02AM (#35580265)
Additionally, the compiler optimizes certain Option<T> types to not require additional storage space.
Re:Optional If Expressions by Measter on Saturday April 15, 2023 @10:16AM (#35580823)
That optimization isn't specific to Option, it works for any enum.