Is there a way to get a Vec<u8> with an alignment (known at compile time) greater than 1? Preferably, where all subsequent uses of the Vec<u8>, including pushing and drop, are safe and correct. #rustlang (I *think* the answer is no, but it would simplify a problem I have.)
-
Show this thread
-
I think you could get away with allocating `Vec<T>` (where `T` has the alignment you want), then using {into,from}_raw_parts to convert between Vec<u8> as you need it. But you cannot realloc or drop with the Vec<u8>.
2 replies 0 retweets 5 likesShow this thread -
N.B. In my case, T = {u8, u16, u32, u64}, so it's safe to re-interpret as bytes. I don't need a fully general solution for any T. (Of course, that is certainly not possible anyway!)
2 replies 0 retweets 3 likesShow this thread -
Replying to @burntsushi5
Does it have to be Vec<u8> exactly? Otherwise, it shouldn't be too hard to make an AlignedBytes<T> that presents an API like Vec<u8>.
1 reply 0 retweets 0 likes
I think that's probably similar to my follow-up tweet, yeah. In my case, this is about avoiding the addition of another type parameter. I guess given that choice and writing more unsafe, I'll probably go with the additional type parameter.
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.