varx/tech on Nostr: Today's Rust learning: I've been doing this thing where I have a param `foo: &Bar` ...
Today's Rust learning:
I've been doing this thing where I have a param `foo: &Bar` and then I pass it to some function as `&foo` because I've superstitiously stuck & onto everything to make the compiler happy. Turns out this creates a double reference; that only works because the compiler is automatically dereferencing the first layer to make things match up. My `foo` is already a reference, so I can pass that reference.
This clears some things up. :-) I'm still missing something about borrowing, but I'll get there.
(Thanks to cargo-clippy for illuminating this!)
I've been doing this thing where I have a param `foo: &Bar` and then I pass it to some function as `&foo` because I've superstitiously stuck & onto everything to make the compiler happy. Turns out this creates a double reference; that only works because the compiler is automatically dereferencing the first layer to make things match up. My `foo` is already a reference, so I can pass that reference.
This clears some things up. :-) I'm still missing something about borrowing, but I'll get there.
(Thanks to cargo-clippy for illuminating this!)