[][src]Struct chromium::UniqueStr

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

A struct for unique str views with a stable layout.

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

Trait Implementations

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

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

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

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

Debug prints as a slice would.

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

fn default() -> Self[src]

Defaults to an empty string.

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

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

type Target = str

The resulting type after dereferencing.

impl<'a> DerefMut for UniqueStr<'a>[src]

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

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

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

Auto Trait Implementations

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

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

impl<'a> Unpin for UniqueStr<'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.