You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi I had a question regarding the safety of remove_alias. The safety explanation is a bit hard for me to understand. Especially this part:
You must consume the adapted iterator in a loop that does not allow multiple yielded items to exist in the same scope. Each yielded item must have a completely non-overlapping lifetime from all the others.
I kinda think you mean that it's unsafe to have multiple chuncks pointing to overlapping parts of the same data, but I'm not sure. Could you help me understand it a bit better?
In my project I need a fixed size array of nibbles, which is one of the reasons I'm using bit_vec in my project. I tried to make a simple example of how I use it:
use bitvec::prelude::{BitArray,BitSlice,Lsb0};#[derive(Clone,Copy,Debug,PartialEq,Eq)]pubstructNibble(BitArray<u8,Lsb0>);implNibble{pubconstBITS:usize = 4;pubconstMAX:u8 = 2u8.pow(Self::BITSasu32);pubfnnew(value:u8) -> Self{assert!(value < Self::MAX);Nibble(BitArray::new(value))}pubfnas_bitslice(&self) -> &BitSlice<u8,Lsb0>{&self.0[0..Self::BITS]}}fnexample(nibbles:&[Nibble;40]) -> BitArray<[u8;20],Lsb0>{letmut result = BitArray::ZERO;
nibbles.iter().map(Nibble::as_bitslice).zip(unsafe{ result.chunks_mut(Nibble::BITS).remove_alias()}).for_each(|(incoming, outgoing)|{
outgoing.copy_from_bitslice(incoming);});
result
}
Is this safe? Is this an XY problem and should I use a different method?
The text was updated successfully, but these errors were encountered:
I think it might've been an XY problem. I'm still hoping for the explanation regarding safety though. Just out of curiosity. Maybe you have an even better solution.
Hi I had a question regarding the safety of
remove_alias
. The safety explanation is a bit hard for me to understand. Especially this part:I kinda think you mean that it's unsafe to have multiple chuncks pointing to overlapping parts of the same data, but I'm not sure. Could you help me understand it a bit better?
In my project I need a fixed size array of nibbles, which is one of the reasons I'm using bit_vec in my project. I tried to make a simple example of how I use it:
Is this safe? Is this an XY problem and should I use a different method?
The text was updated successfully, but these errors were encountered: