[][src]Struct chromium::UniqueSlice

#[repr(C)]
pub struct UniqueSlice<'a, T> where
    T: StableLayout
{ /* 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 SharedSlice 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 UniqueSlice 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 UniqueSlice 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 `UniqueSlice<'a, u8>`
typedef struct {
  uint8_t *ptr;
  uintptr_t len;
} UniqueSlice_u8;

Trait Implementations

impl<'a, T: Debug> Debug for UniqueSlice<'a, T> where
    T: StableLayout
[src]

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

Debug prints as a slice would.

impl<'a, T> Default for UniqueSlice<'a, T> where
    T: StableLayout
[src]

fn default() -> Self[src]

Defaults to an empty slice.

let unique: UniqueSlice<'static, i32> = UniqueSlice::default();
assert_eq!(unique.len(), 0);

impl<'a, T> Deref for UniqueSlice<'a, T> where
    T: StableLayout
[src]

type Target = [T]

The resulting type after dereferencing.

impl<'a, T> DerefMut for UniqueSlice<'a, T> where
    T: StableLayout
[src]

impl<'a, T> From<&'a mut [T]> for UniqueSlice<'a, T> where
    T: StableLayout
[src]

impl<'a, T> From<UniqueSlice<'a, T>> for &'a mut [T] where
    T: StableLayout
[src]

impl<'a, T: StableLayout> StableLayout for UniqueSlice<'a, T>[src]

Auto Trait Implementations

impl<'a, T> !Send for UniqueSlice<'a, T>

impl<'a, T> !Sync for UniqueSlice<'a, T>

impl<'a, T> Unpin for UniqueSlice<'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.