#AdventOfCode #Day5 with #rust
-
#AdventOfCode #Day5 with #rust
today I got to use the <_> thing for the first time. I wonder what its name is. Cylone face? Crab operator? Anyway, nice.
Also, deeply confused that both of these work
if current.end() >= other_ref.start()
vs
if *current.end() >= *other_ref.start()
I think this is another case or references being more than "just" pointers.
https://gist.github.com/riffraff/052676798bf2d12c899e9a0ef964d0d1
-
#AdventOfCode #Day5 with #rust
today I got to use the <_> thing for the first time. I wonder what its name is. Cylone face? Crab operator? Anyway, nice.
Also, deeply confused that both of these work
if current.end() >= other_ref.start()
vs
if *current.end() >= *other_ref.start()
I think this is another case or references being more than "just" pointers.
https://gist.github.com/riffraff/052676798bf2d12c899e9a0ef964d0d1
@riffraff Interesting, i took a peek at the docs. Primitive types implement PartialEq also between references. Just to make things easier, I think, without having to sprinkle the code with *.
E.g. for i32 https://doc.rust-lang.org/stable/std/primitive.i32.html#impl-PartialEq-for-i32 and if you look at the source you'll find this beauty
fn eq(&self, other: &Self) -> bool { *self == *other }
Since the standard library doesn't mention PartialEq between values of primitive types that must be implemented directly in the compiler. Which is pretty cool.
-
@riffraff Interesting, i took a peek at the docs. Primitive types implement PartialEq also between references. Just to make things easier, I think, without having to sprinkle the code with *.
E.g. for i32 https://doc.rust-lang.org/stable/std/primitive.i32.html#impl-PartialEq-for-i32 and if you look at the source you'll find this beauty
fn eq(&self, other: &Self) -> bool { *self == *other }
Since the standard library doesn't mention PartialEq between values of primitive types that must be implemented directly in the compiler. Which is pretty cool.
@ormai yeah I think it's interacting with this
https://doc.rust-lang.org/book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methodswhich is indeed very ergonomic, but confuses the hell out me, cause e.g. >= works but arithmetic does not :)