mcc on Nostr: In Rust, is there any reason at all to make a Option<Vec<Thing>> instead of a ...
In Rust, is there any reason at all to make a Option<Vec<Thing>> instead of a Vec<Thing> if the semantics of "None" here just mean "there are no Things"? Like if you create and never populate an empty vec that's never gonna allocate on the heap right?
I guess one way of looking at it might be that Option<Vec<>> might be taking a small performance hit in exchange for the ability to catch None via match {}, but that probably is only ergonomics
Published at
2024-12-01 19:13:09Event JSON
{
"id": "2076c55d9fee900c54b43ba1a0dd3319485ffedc589300df1ac896feb39288da",
"pubkey": "a3162b9720f6b515ac4bd22d5ea4abf0f85f5685130dca40f46fe684fe85b255",
"created_at": 1733080389,
"kind": 1,
"tags": [
[
"proxy",
"https://mastodon.social/users/mcc/statuses/113579156379450156",
"activitypub"
]
],
"content": "In Rust, is there any reason at all to make a Option\u003cVec\u003cThing\u003e\u003e instead of a Vec\u003cThing\u003e if the semantics of \"None\" here just mean \"there are no Things\"? Like if you create and never populate an empty vec that's never gonna allocate on the heap right?\n\nI guess one way of looking at it might be that Option\u003cVec\u003c\u003e\u003e might be taking a small performance hit in exchange for the ability to catch None via match {}, but that probably is only ergonomics",
"sig": "8bcdc3c265d180feea7063c6c59200dd65e128f2320409e0663624446a16cc3de99927f327c76c62f3132311c4a560e6090be0eca2c5e5c9de8ffb6f00081dee"
}