# Struct bytes::buf::UninitSlice [−] [src]

    #[repr(transparent)]pub struct UninitSlice(_);

Uninitialized byte slice.

Returned by `BufMut::chunk_mut()`, the referenced byte slice may be uninitialized. The wrapper provides safe access without introducing undefined behavior.

The safety invariants of this wrapper are:

1. Reading from an `UninitSlice` is undefined behavior.
2. Writing uninitialized bytes to an `UninitSlice` is undefined behavior.

The difference between `&mut UninitSlice` and `&mut [MaybeUninit<u8>]` is that it is possible in safe code to write uninitialized bytes to an `&mut [MaybeUninit<u8>]`, which this type prohibits.

## Implementations

### `impl UninitSlice` [src]

#### `pub unsafe fn from_raw_parts_mut<'a>(
ptr: *mut u8,
len: usize
) -> &'a mut UninitSlice` [src]

Create a `&mut UninitSlice` from a pointer and a length.

# Safety

The caller must ensure that `ptr` references a valid memory region owned by the caller representing a byte slice for the duration of `'a`.

# Examples

    use bytes::buf::UninitSlice;

    let bytes = b"hello world".to_vec();
    let ptr = bytes.as_ptr() as *mut _;
    let len = bytes.len();

    let slice = unsafe { UninitSlice::from_raw_parts_mut(ptr, len) };

#### `pub fn write_byte(&mut self, index: usize, byte: u8)` [src]

Write a single byte at the specified offset.

# Panics

The function panics if `index` is out of bounds.

# Examples

    use bytes::buf::UninitSlice;

    let mut data = [b'f', b'o', b'o'];
    let slice = unsafe { UninitSlice::from_raw_parts_mut(data.as_mut_ptr(), 3) };

    slice.write_byte(0, b'b');

    assert_eq!(b"boo", &data[..]);

#### `pub fn copy_from_slice(&mut self, src: &[u8])` [src]

Copies bytes from `src` into `self`.

The length of `src` must be the same as `self`.

# Panics

The function panics if `src` has a different length than `self`.

# Examples

    use bytes::buf::UninitSlice;

    let mut data = [b'f', b'o', b'o'];
    let slice = unsafe { UninitSlice::from_raw_parts_mut(data.as_mut_ptr(), 3) };

    slice.copy_from_slice(b"bar");

    assert_eq!(b"bar", &data[..]);

#### `pub fn as_mut_ptr(&mut self) -> *mut u8` [src]

Return a raw pointer to the slice’s buffer.

# Safety

The caller must not read from the referenced memory and must not write uninitialized bytes to the slice either.

# Examples

    use bytes::BufMut;

    let mut data = [0, 1, 2];
    let mut slice = &mut data[..];
    let ptr = BufMut::chunk_mut(&mut slice).as_mut_ptr();

#### `pub fn len(&self) -> usize` [src]

Returns the number of bytes in the slice.

# Examples

    use bytes::BufMut;

    let mut data = [0, 1, 2];
    let mut slice = &mut data[..];
    let len = BufMut::chunk_mut(&mut slice).len();

    assert_eq!(len, 3);

## Trait Implementations

### `impl Debug for UninitSlice` [src]

#### `fn fmt(&self, fmt: &mut Formatter<'_>) -> Result` [src]

Formats the value using the given formatter. Read more

### `impl Index<Range<usize>> for UninitSlice` [src]

#### `type Output = UninitSlice`

The returned type after indexing.

#### `fn index(&self, index: Range<usize>) -> &UninitSlice` [src]

Performs the indexing (`container[index]`) operation.

### `impl Index<RangeFrom<usize>> for UninitSlice` [src]

#### `type Output = UninitSlice`

The returned type after indexing.

#### `fn index(&self, index: RangeFrom<usize>) -> &UninitSlice` [src]

Performs the indexing (`container[index]`) operation.

### `impl Index<RangeFull> for UninitSlice` [src]

#### `type Output = UninitSlice`

The returned type after indexing.

#### `fn index(&self, index: RangeFull) -> &UninitSlice` [src]

Performs the indexing (`container[index]`) operation.

### `impl Index<RangeInclusive<usize>> for UninitSlice` [src]

#### `type Output = UninitSlice`

The returned type after indexing.

#### `fn index(&self, index: RangeInclusive<usize>) -> &UninitSlice` [src]

Performs the indexing (`container[index]`) operation.

### `impl Index<RangeTo<usize>> for UninitSlice` [src]

#### `type Output = UninitSlice`

The returned type after indexing.

#### `fn index(&self, index: RangeTo<usize>) -> &UninitSlice` [src]

Performs the indexing (`container[index]`) operation.

### `impl Index<RangeToInclusive<usize>> for UninitSlice` [src]

#### `type Output = UninitSlice`

The returned type after indexing.

#### `fn index(&self, index: RangeToInclusive<usize>) -> &UninitSlice` [src]

Performs the indexing (`container[index]`) operation.

### `impl IndexMut<Range<usize>> for UninitSlice` [src]

#### `fn index_mut(&mut self, index: Range<usize>) -> &mut UninitSlice` [src]

Performs the mutable indexing (`container[index]`) operation.

### `impl IndexMut<RangeFrom<usize>> for UninitSlice` [src]

#### `fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut UninitSlice` [src]

Performs the mutable indexing (`container[index]`) operation.

### `impl IndexMut<RangeFull> for UninitSlice` [src]

#### `fn index_mut(&mut self, index: RangeFull) -> &mut UninitSlice` [src]

Performs the mutable indexing (`container[index]`) operation.

### `impl IndexMut<RangeInclusive<usize>> for UninitSlice` [src]

#### `fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut UninitSlice` [src]

Performs the mutable indexing (`container[index]`) operation.

### `impl IndexMut<RangeTo<usize>> for UninitSlice` [src]

#### `fn index_mut(&mut self, index: RangeTo<usize>) -> &mut UninitSlice` [src]

Performs the mutable indexing (`container[index]`) operation.

### `impl IndexMut<RangeToInclusive<usize>> for UninitSlice` [src]

#### `fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut UninitSlice` [src]

Performs the mutable indexing (`container[index]`) operation.

## Auto Trait Implementations

### `impl RefUnwindSafe for UninitSlice`

### `impl Send for UninitSlice`

### `impl !Sized for UninitSlice`

### `impl Sync for UninitSlice`

### `impl Unpin for UninitSlice`

### `impl UnwindSafe for UninitSlice`

## Blanket Implementations

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `pub fn type_id(&self) -> TypeId` [src]

Gets the `TypeId` of `self`. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow(&self) -> &T` [src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow_mut(&mut self) -> &mut T` [src]

Mutably borrows from an owned value. Read more