New enum layout optimizations in the latest Rust Nightly!
bool - Option<bool> is 1 byte
char - Option<char> is 4 bytes
enum - Option<Ordering> and Option<Option<bool>> are 1 byte
! ("Never") - Option<!> = (); Result<T, !> = T
great work, @eddyb_r!
-
Show this thread
-
would be nice to annotate an enum and automatically box enums which were bigger than some size, e.g. 4 bytes
1 reply 0 retweets 0 likes -
never gonna happen in rust, sorry
2 replies 0 retweets 0 likes -
You could make a macro that does it? ;)
1 reply 0 retweets 0 likes -
possibly, but hinting to the compiler that I don't mind boxing would be ideal. Couple of examples from my own code base - 1) https://github.com/locka99/opcua/blob/master/types/src/variant.rs …, 2) https://github.com/locka99/opcua/blob/master/types/src/supported_message.rs …
2 replies 0 retweets 0 likes -
Like @Gankro points out, that's just not going to happen in Rust. Rust's philosophy is around always being as fast as possible. Invisibly making things possibly slower runs against that.
2 replies 0 retweets 1 like -
@withoutboats has been advocating for #[repr(boxed)] which would sorta do this1 reply 0 retweets 2 likes
Sometimes a smaller size is faster, even with an allocation. We shall see!
-
-
The important difference is that the size of each variant is not visible, so if you just said “box variants over size N” it wouldn’t be obvious what that does
1 reply 0 retweets 2 likes - 2 more replies
New conversation -
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.