arrow2
arrow2 copied to clipboard
Export `values` of MutableArray
For example:
pub struct MutableBinaryArray<O: Offset> {
data_type: DataType,
offsets: MutableBuffer<O>,
values: MutableBuffer<u8>,
validity: Option<MutableBitmap>,
}
When we want to add methods into MutableBinaryArray
, we can't access the fields like values
...
The rational is that values
and offsets
are coupled: we can't expose values
as a mut reference because the user may truncate it, leading to UB.
We can still offer a &mut [u8]
reference to it.
Ok. Get it, seems we should build values
and offsets
on my own then construct them into MutableArray
.
We don't like TryPush
method in this MutableArray
, if our array is not null, just need to push the values and offsets without option wrap.
You mean to avoid the conditional branch that checks for the validity, right? I agree.
There is a use-case here to introduce an auxiliary struct that just cares about offsets, values and its invariants, and have the MutableBinaryArray
use it. This way both you and MutableBinaryArray
can use it, and you do not have to worry about unsafe
on your side.
Yes, that's right. Since MutableBinaryArray
is not very complex now, we can have our own NoneNullMutableBinaryArray
instead.