Manishearth/triomphe

Add SliceArc

stepancheg opened this issue · 0 comments

struct SliceArc<T> {
  data: NonNull<T>,
  len: usize,
}

impl Deref for SliceArc<T> {
  type Target = &[T];

  fn deref(&self) -> &[T] {
    slice::from_raw_parts(self.data, self.len)
  }
}

When len == 0, it does no allocation, const-constructible, data is dangling pointer.

When len != 0, data holds a pointer to slice data, and arc headers lies in memory before the data.