Hacker News new | ask | show | jobs
by ChrisSD 2538 days ago
MaybeUninit<T> is very welcome considering mem::uninitialized turned out to be such a mistake. I only tried using it once which dissuaded me from trying again, which was probably for the best.

I'm still looking forward to const generics and a more usable const fn. In a way it's a shame Rust doesn't have a purely constant function in the interim. But a hybrid function will be more versatile once it allows some form of looping.

The last thing on my wishlist is extern types (aka opaque types aka void *). The current workaround using a pointer to a [i8; 0] type relies on LLVM's particular handling of such pointers and always looks weird in rust.

1 comments

I might be revealing myself as a novice rust programmer here, but can't you use 'ptr : * const()' as an opaque pointer type?

It's how I interface with C and C++ callback functions.

You can, but there’s reasons a real external type feature is useful: https://github.com/rust-lang/rfcs/blob/master/text/1861-exte...
According to the nomicon[0], using a zero sized array in a repr(C) struct is the best practice for type safety. I also seem to remember someone saying the zero sized array is analogous to how LLVM bitcode represents void* in C.

[0] https://doc.rust-lang.org/nomicon/ffi.html#representing-opaq...