This fascinating snippet of Rust does some tricky work with no allocations or copying, type- and memory-safely: https://gist.github.com/Aatch/5734372
@andy_matuschak right, that part I understood, and is very neat. But isn't the wrapper itself a new allocation?
-
-
@avibryant It’s like this in C: typedef union { void *Some; bool isNothing } Option Option foo(void *x) { return (Option) {.Some = x}. } -
@avibryant (except much safer in a number of ways) In that snippet, a structure is being returned on the stack, like the Option in my C. -
@andy_matuschak got it, thank you. Out of curiosity: does the compiler have special knowledge of Option, or is it library code? -
@avibryant No, it’s library code. Nothing special. https://github.com/mozilla/rust/blob/master/src/libcore/option.rs …
End of conversation
New conversation -
-
-
@andy_matuschak ... or does the compiler optimize away Option types?Thanks. Twitter will use this to make your timeline better. UndoUndo
-
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.