-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Closed
Description
Currently, raw::Slice is implemented implemented as len, data, and Vec is implemented as len, cap, data. This means that the following code requires a branch, which is extremely unfortunate for my use-case:
enum MaybeOwnedBuffer<'a> {
OwnedBuffer(Vec<u8>),
BorrowedBuffer(raw::Slice<u8>, ContravariantLifetime<'a>),
}
impl<'a> MaybeOwnedBuffer<'a> {
#[inline(always)]
unsafe fn as_raw_slice(&self) -> raw::Slice<u8> {
match *self {
OwnedBuffer(ref v) => mem::transmute(v.as_slice()),
BorrowedBuffer(ref s, _) => *s,
}
}
}
Ideally, the order of Vec's fields should be changed to len, data, cap to make conversion free.
Thoughts?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels