Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SliceArc #52

Open
stepancheg opened this issue Nov 17, 2022 · 0 comments
Open

Add SliceArc #52

stepancheg opened this issue Nov 17, 2022 · 0 comments

Comments

@stepancheg
Copy link
Contributor

stepancheg commented Nov 17, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant