[−][src]Struct chromium::StableVec
A struct for the parts of a Vec
with a stable layout.
Unsafety
Because this type is primarily intended to help unsafe Rust we should discuss the precise guarantees offered:
- Validity Invariants
- The data layout is a
*mut T
,usize
,usize
.
- The data layout is a
- Soundness Invariants
- The
*mut T
must point to the start of a validVec<T>
allocation. - The first
usize
must be the correct length of that validVec<T>
. - The second
usize
must be the correct capacity of that validVec<T>
. - The memory is owned by the
StableVec
and is allocated from Rust's Global Allocator.- You must not turn this type back into a
Vec
in a Rust runtime with a different global allocator than the one is was created with. At the moment (2020-03-06) it happens to be the case that the default Rust global allocator is process-wide on Windows / Mac / Linux.
- You must not turn this type back into a
- The
If you drop a StableVec
without turning it back into a Vec
then the
memory leaks.
When you use this type with the C ABI, remember that the C ABI does not
support generic types or repr(Rust)
types!
If you select a particular type for T
that is compatible with the C ABI,
such as u8
or i32
, then that particular monomorphization of
SharedSlice
will be C ABI compatible as well. For example, if your element
type were u8
then it would be equivalent layout to the following C
declaration:
#include <stdint.h>
// Identical layout to `StableVec<u8>`
typedef struct {
uint8_t *ptr;
uintptr_t len;
uintptr_t cap;
} StableVec_u8;
Trait Implementations
impl<T: Debug> Debug for StableVec<T> where
T: StableLayout,
[src]
T: StableLayout,
impl<T> Default for StableVec<T> where
T: StableLayout,
[src]
T: StableLayout,
fn default() -> Self
[src]
Defaults to an empty vec.
let sv: StableVec<i32> = StableVec::default(); assert_eq!(sv.len(), 0);
impl<T> Deref for StableVec<T> where
T: StableLayout,
[src]
T: StableLayout,
impl<T> DerefMut for StableVec<T> where
T: StableLayout,
[src]
T: StableLayout,
impl<T> From<StableVec<T>> for Vec<T> where
T: StableLayout,
[src]
T: StableLayout,
impl<T> From<Vec<T>> for StableVec<T> where
T: StableLayout,
[src]
T: StableLayout,
impl<T: StableLayout> StableLayout for StableVec<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,