[][src]Struct chromium::SharedStr

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

A struct for shared str views with a stable layout.

This is a repr(C) variant of &str. If you want a variant of &mut str then you should use UniqueStr 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 u8 and then a usize.
  • Soundness Invariants
    • The *const u8 must point to the start of a valid &str.
    • The usize must be the correct length of that valid &str.
    • For as long as the SharedStr exists the memory in question has a shared borrow over it (tracked via PhantomData).
    • The memory must contain value UTF-8 data.

This type matches up with the following C layout:

#include <stdint.h>
// Identical layout to `SharedStr<'a>`
typedef struct {
  uint8_t const *ptr;
  uintptr_t len;
} SharedStr;

Trait Implementations

impl<'a> Clone for SharedStr<'a>[src]

impl<'a> Copy for SharedStr<'a>[src]

impl<'a> Debug for SharedStr<'a>[src]

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

Debug prints as a slice would.

impl<'a> Default for SharedStr<'a>[src]

fn default() -> Self[src]

Defaults to an empty string.

let shared: SharedStr<'static> = SharedStr::default();
assert_eq!(shared.len(), "".len());

impl<'a> Deref for SharedStr<'a>[src]

type Target = str

The resulting type after dereferencing.

impl<'a> From<&'a str> for SharedStr<'a>[src]

impl<'a> From<SharedStr<'a>> for &'a str[src]

impl<'a> StableLayout for SharedStr<'a>[src]

Auto Trait Implementations

impl<'a> !Send for SharedStr<'a>

impl<'a> !Sync for SharedStr<'a>

impl<'a> Unpin for SharedStr<'a>

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.