[−][src]Struct chromium::UniqueStr
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 ausize
.
- The data layout is a
- 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 viaPhantomData
). - The memory must contain value UTF-8 data.
- The
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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Copy for UniqueStr<'a>
[src]
impl<'a> Debug for UniqueStr<'a>
[src]
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]
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
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,