[][src]Struct chromium::CUniqueSlice

#[repr(C)]
pub struct CUniqueSlice<'a, T> { /* fields omitted */ }

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 a usize.
  • 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 via PhantomData).

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]

fn fmt(&self, f: &mut Formatter) -> Result[src]

Debug prints as a slice would.

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]

type Target = [T]

The resulting type after dereferencing.

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]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.