Daniel aka CyReVolt 🐢 on Nostr: Times when #Rust drives you mad: Hey, just add `&foo[..]` something. No, drop the `&` ...
Times when #Rust drives you mad:
Hey, just add `&foo[..]` something.
No, drop the `&` again.
Hey, add some more `[..]`!
Gosh... I have a struct, say,
`struct Boop { boop: [u8; 32] }`
How do I instantiate it?
I tried
`Boop { boop: vec![0u8; 32] }`
and that didn't work. So I tried
`Boop { boop: vec![0u8; 32].as_slice() }`
and that didn't work either ... because it loses size information, IIUC... #halpz
Published at
2024-02-09 22:13:34Event JSON
{
"id": "a8a5cec8ca7c68958cb54b4d3ad4992097045ec39a99ec4f75b5e698870dd5b2",
"pubkey": "27684482ea0173fda7103c7710eaa65824311bd5d6d35cb6be982a83e13ec2e4",
"created_at": 1707516814,
"kind": 1,
"tags": [
[
"t",
"rust"
],
[
"t",
"halpz"
],
[
"proxy",
"https://mastodon.social/users/CyReVolt/statuses/111903821961552145",
"activitypub"
]
],
"content": "Times when #Rust drives you mad:\n\nHey, just add `\u0026foo[..]` something.\nNo, drop the `\u0026` again.\nHey, add some more `[..]`!\n\nGosh... I have a struct, say,\n`struct Boop { boop: [u8; 32] }`\n\nHow do I instantiate it?\nI tried\n`Boop { boop: vec![0u8; 32] }`\nand that didn't work. So I tried\n`Boop { boop: vec![0u8; 32].as_slice() }`\nand that didn't work either ... because it loses size information, IIUC... #halpz\n\nhttps://files.mastodon.social/media_attachments/files/111/903/807/825/221/165/original/af8c69da94e96b5c.png",
"sig": "f7070fc895a13dc4ab23666e2e7829d24bc54a51e16da0ab464e16fdb29890b6460f9a75e771c3122dd0e850bb6d11a0cff405d4f2214fd6ecc1a8f8bd8813d3"
}