[][src]Struct chromium::SharedSlice

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

A struct for shared slices with a stable layout.

This is a repr(C) variant of &[T]. If you want a variant of &mut [T] then you should use UniqueSlice 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 *const T and then a usize.
  • Soundness Invariants
    • The *const T must point to the start of a valid &[T].
    • The usize must be the correct length of that valid &[T].
    • For as long as the SharedSlice exists the memory in question has a shared 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 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 `SharedSlice<'a, u8>`
typedef struct {
  uint8_t const *ptr;
  uintptr_t len;
} SharedSlice_u8;

Trait Implementations

impl<'a, T> Clone for SharedSlice<'a, T> where
    T: StableLayout
[src]

impl<'a, T> Copy for SharedSlice<'a, T> where
    T: StableLayout
[src]

impl<'a, T: Debug> Debug for SharedSlice<'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 SharedSlice<'a, T> where
    T: StableLayout
[src]

fn default() -> Self[src]

Defaults to an empty slice.

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

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

type Target = [T]

The resulting type after dereferencing.

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

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

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

Auto Trait Implementations

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

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

impl<'a, T> Unpin for SharedSlice<'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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.