[−][src]Struct chromium::UniqueSlice
A struct for unique slices with a stable layout.
This is a repr(C)
variant of &mut [T]
. If you want a variant of &[T]
then you should use SharedSlice
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 T
and then ausize
.
- The data layout is a
- Soundness Invariants
- The
*mut T
must point to the start of a valid&mut [T]
. - The
usize
must be the correct length of that valid&mut [T]
. - For as long as the
UniqueSlice
exists the memory in question has a unique borrow over it (tracked viaPhantomData
).
- The
When you use this type with the C ABI, remember that the C ABI does not
support generic types or repr(Rust)
types!
If you select a particular type for T
that is compatible with the C ABI,
such as u8
or i32
, then that particular monomorphization of
UniqueSlice
will be C ABI compatible as well. For example, if your
element type were u8
then it would be equivalent layout to the following C
declaration:
#include <stdint.h>
// Identical layout to `UniqueSlice<'a, u8>`
typedef struct {
uint8_t *ptr;
uintptr_t len;
} UniqueSlice_u8;
Trait Implementations
impl<'a, T: Debug> Debug for UniqueSlice<'a, T> where
T: StableLayout,
[src]
T: StableLayout,
impl<'a, T> Default for UniqueSlice<'a, T> where
T: StableLayout,
[src]
T: StableLayout,
fn default() -> Self
[src]
Defaults to an empty slice.
let unique: UniqueSlice<'static, i32> = UniqueSlice::default(); assert_eq!(unique.len(), 0);
impl<'a, T> Deref for UniqueSlice<'a, T> where
T: StableLayout,
[src]
T: StableLayout,
impl<'a, T> DerefMut for UniqueSlice<'a, T> where
T: StableLayout,
[src]
T: StableLayout,
impl<'a, T> From<&'a mut [T]> for UniqueSlice<'a, T> where
T: StableLayout,
[src]
T: StableLayout,
impl<'a, T> From<UniqueSlice<'a, T>> for &'a mut [T] where
T: StableLayout,
[src]
T: StableLayout,
fn from(unique: UniqueSlice<'a, T>) -> Self
[src]
impl<'a, T: StableLayout> StableLayout for UniqueSlice<'a, T>
[src]
Auto Trait Implementations
impl<'a, T> !Send for UniqueSlice<'a, T>
impl<'a, T> !Sync for UniqueSlice<'a, T>
impl<'a, T> Unpin for UniqueSlice<'a, T>
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>,