copy_stack_vec/vec/array/
as_ptr.rs

1// This file is part of copy-stack-vec.
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4// Crate imports
5use crate::vec::CopyStackVec;
6
7impl<T: Copy, const N: usize> CopyStackVec<T, N> {
8    /// Returns a raw pointer to the start of the backing storage.
9    ///
10    /// Only the first `len` elements are logically initialized as `T`. Code that
11    /// dereferences this pointer must:
12    ///
13    /// - treat `self.len` as the number of initialized elements, and
14    /// - avoid reading from `ptr.add(i)` for any `i >= self.len`.
15    ///
16    /// Writing to the memory beyond `len` is allowed from Rust’s point of view,
17    /// but it does **not** update `len`, and such writes will not be reflected in
18    /// the logical contents of the `CopyStackVec`.
19    #[inline]
20    pub fn as_ptr(&self) -> *const T {
21        self.buf.as_ptr()
22    }
23
24    /// Returns a mutable raw pointer to the start of the backing storage.
25    ///
26    /// Only the first `len` elements are logically initialized as `T`. Code that
27    /// dereferences this pointer must:
28    ///
29    /// - treat `self.len` as the number of initialized elements, and
30    /// - avoid reading from `ptr.add(i)` for any `i >= self.len`.
31    ///
32    /// Writing to the memory beyond `len` is allowed from Rust’s point of view,
33    /// but it does **not** update `len`, and such writes will not be reflected in
34    /// the logical contents of the `CopyStackVec`.
35    #[inline]
36    pub fn as_mut_ptr(&mut self) -> *mut T {
37        self.buf.as_mut_ptr()
38    }
39}