[−][src]Struct chromium::StableString
A struct for the parts of a String
with a stable
layout.
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 T
,usize
,usize
.
- The data layout is a
- Soundness Invariants
- The
*mut T
must point to the start of a validString
allocation. - The first
usize
must be the correct length of that validString
. - The second
usize
must be the correct capacity of that validString
. - The memory is owned by the
String
and is allocated from Rust's Global Allocator.- You must not turn this type back into a
String
in a Rust runtime with a different global allocator than the one is was created with. At the moment (2020-03-06) it happens to be the case that the default Rust global allocator is process-wide on Windows / Mac / Linux.
- You must not turn this type back into a
- The memory must contain valid UTF-8 data.
- The
If you drop a StableString
without turning it back into a StableString
then the memory leaks.
#include <stdint.h>
// Identical layout to `StableString`
typedef struct {
uint8_t *ptr;
uintptr_t len;
uintptr_t cap;
} StableString;
Trait Implementations
impl Debug for StableString
[src]
impl Default for StableString
[src]
fn default() -> Self
[src]
Defaults to an empty vec.
let sv: StableString = StableString::default(); assert_eq!(sv.len(), 0);
impl Deref for StableString
[src]
impl DerefMut for StableString
[src]
impl From<StableString> for String
[src]
fn from(sv: StableString) -> Self
[src]
impl From<String> for StableString
[src]
impl StableLayout for StableString
[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, 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>,