Next fun rust question: how to use mem::uninit in a struct and safely drop when not fully initialised.
-
Show this thread
-
Replying to @Erstejahre @rustlang
Out of curiosity: How do you get a partially initialized struct?
2 replies 0 retweets 0 likes -
Exceptions (including Rust panics) are the classic way to get such objects. Start with two uninitialized fields, init one, get an exception initializing the other. This is a tricky situation to recover from.
2 replies 0 retweets 0 likes -
I agree that Exceptions can cause corrupted state. But shouldn’t a Rust panic “terminate” the thread and therefore disallow access to the instance... How can an instance remain accessable after a panic occured?
1 reply 0 retweets 0 likes -
Rust panics do not always immediately terminate the thread. By default they try to unwind the stack, which may call the Drop impl of your partly-constructed object. Also Rust panics can be caught. You shouldn't normally catch them but for example it's UB to unwind into FFI.
2 replies 0 retweets 1 like
Additionally, mutexes can be accessed by multiple threads. A panic with one poisons the mutex, but if you really want the value you can technically still get it.
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.