This fascinating snippet of Rust does some tricky work with no allocations or copying, type- and memory-safely: https://gist.github.com/Aatch/5734372
-
-
Replying to @andy_matuschak
@andy_matuschak it at least allocates the Some() on line 59, right? Very cool, though.1 reply 0 retweets 0 likes -
Replying to @avibryant
@avibryant Ah, sorry, I wasn’t counting stack allocations because they’re not what I normally worry about. Yes.1 reply 0 retweets 0 likes -
Replying to @andy_matuschak
@andy_matuschak hm, how does that Some avoid being heap allocated? It gets returned from the get_string call. (I don't know Rust well).1 reply 0 retweets 0 likes -
Replying to @avibryant
@avibryant The Some wraps a reference to an inner pointer of the json argument. The “lifetime parameters” ensure the safety of that trick.1 reply 0 retweets 0 likes -
Replying to @andy_matuschak
@andy_matuschak right, that part I understood, and is very neat. But isn't the wrapper itself a new allocation?2 replies 0 retweets 0 likes
@andy_matuschak ... or does the compiler optimize away Option types?
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.