[−][src]Struct chromium::SharedStr
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 ausize
.
- The data layout is a
- 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 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 `SharedStr<'a>`
typedef struct {
uint8_t const *ptr;
uintptr_t len;
} SharedStr;
Trait Implementations
impl<'a> Clone for SharedStr<'a>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Copy for SharedStr<'a>
[src]
impl<'a> Debug for SharedStr<'a>
[src]
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]
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
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>,