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!)
Published at
2024-03-14 03:22:05Event JSON
{
"id": "c6c9c67d9945264f149136c8e35ee76f7ffc801440b6bf8cd650c81647f60dab",
"pubkey": "8e3ac11e1cfbd1959ffff89d016fd2a6c159c4880cf4fe0274ac3852e21f2b88",
"created_at": 1710386525,
"kind": 1,
"tags": [
[
"proxy",
"https://infosec.exchange/users/varx/statuses/112091891310087913",
"activitypub"
]
],
"content": "Today's Rust learning:\n\nI've been doing this thing where I have a param `foo: \u0026Bar` and then I pass it to some function as `\u0026foo` because I've superstitiously stuck \u0026 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.\n\nThis clears some things up. :-) I'm still missing something about borrowing, but I'll get there.\n\n(Thanks to cargo-clippy for illuminating this!)",
"sig": "66aaadbec9804117dd4a971657270a9b8de258a30d614a30d7275f020a3a16b5e34beff1fbdf24575998df9a7ca7571827ac8382f4475c15cb2ea7ef4452547c"
}