cpp_core/vector_ops.rs
1//! Traits for common operations on C++ vectors.
2
3/// Provides access to the underlying memory buffer.
4pub trait Data {
5 /// Return type of `data()` function.
6 type Output;
7 /// Returns a pointer to the underlying memory buffer.
8 ///
9 /// # Safety
10 ///
11 /// The caller must make sure `self` contains a valid pointer. This function
12 /// may invoke arbitrary foreign code, so no safety guarantees can be made.
13 unsafe fn data(&self) -> Self::Output;
14}
15
16/// Provides mutable access to the underlying memory buffer.
17pub trait DataMut {
18 /// Return type of `data_mut()` function.
19 type Output;
20 /// Returns a pointer to the underlying memory buffer.
21 ///
22 /// # Safety
23 ///
24 /// The caller must make sure `self` contains a valid pointer. This function
25 /// may invoke arbitrary foreign code, so no safety guarantees can be made.
26 unsafe fn data_mut(&self) -> Self::Output;
27}
28
29/// Provides access to the size of the collection.
30pub trait Size {
31 /// Returns number of the elements in the underlying buffer.
32 ///
33 /// # Safety
34 ///
35 /// The caller must make sure `self` contains a valid pointer. This function
36 /// may invoke arbitrary foreign code, so no safety guarantees can be made.
37 unsafe fn size(&self) -> usize;
38}