[−][src]Struct chromium::CUniqueSlice
A struct for unique slices with a stable layout.
This is a repr(C)
variant of &mut [T]
. If you want a variant of &[T]
then you should use CSharedSlice
instead.
Rationale for using this type is given in the crate level docs.
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
and then ausize
.
- The data layout is a
- Soundness Invariants
- The
*mut T
must point to the start of a valid&mut [T]
. - The
usize
must be the correct length of that valid&mut [T]
. - For as long as the
CUniqueSlice
exists the memory in question has a unique borrow over it (tracked viaPhantomData
).
- The
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
CSharedSlice
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 `CUniqueSlice<'a, u8>`
typedef struct {
uint8_t *ptr;
uintptr_t len;
} CUniqueSlice_u8;
Methods
impl<'a, T> CUniqueSlice<'a, T>
[src]
pub fn empty_slice() -> Self
[src]
Gives an empty slice.
This will become const
once
rust-lang/rust#57349
happens.
let c_shared: CUniqueSlice<'static, i32> = CUniqueSlice::empty_slice(); assert_eq!(c_shared.len(), 0);
Trait Implementations
impl<'a, T: Debug> Debug for CUniqueSlice<'a, T>
[src]
impl<'a, T> Default for CUniqueSlice<'a, T>
[src]
fn default() -> Self
[src]
Defaults to an empty slice.
let c_shared: CUniqueSlice<'static, i32> = CUniqueSlice::default(); assert_eq!(c_shared.len(), 0);
impl<'a, T> Deref for CUniqueSlice<'a, T>
[src]
impl<'a, T> DerefMut for CUniqueSlice<'a, T>
[src]
impl<'a, T> From<&'a mut [T]> for CUniqueSlice<'a, T>
[src]
impl<'a, T> From<CUniqueSlice<'a, T>> for &'a mut [T]
[src]
fn from(c_shared: CUniqueSlice<'a, T>) -> Self
[src]
Auto Trait Implementations
impl<'a, T> !Send for CUniqueSlice<'a, T>
impl<'a, T> !Sync for CUniqueSlice<'a, T>
impl<'a, T> Unpin for CUniqueSlice<'a, T>
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>,