# bytes::BytesMut - Rust
API documentation for the Rust `BytesMut` struct in crate `bytes`.
Keywords: rust, rustlang, rust-lang, BytesMut

# [−] [src] Struct bytes::BytesMut

    pub struct BytesMut { /* fields omitted */ }

A unique reference to a contiguous slice of memory.

`BytesMut` represents a unique view into a potentially shared memory region. Given the uniqueness guarantee, owners of `BytesMut` handles are able to mutate the memory.

`BytesMut` can be thought of as containing a `buf: Arc<Vec<u8>>`, an offset into `buf`, a slice length, and a guarantee that no other `BytesMut` for the same `buf` overlaps with its slice. That guarantee means that a write lock is not required.

# Growth

`BytesMut`'s `BufMut` implementation will implicitly grow its buffer as necessary. However, explicitly reserving the required space up-front before a series of inserts will be more efficient.

# Examples

    use bytes::{BytesMut, BufMut};

    let mut buf = BytesMut::with_capacity(64);

    buf.put_u8(b'h');
    buf.put_u8(b'e');
    buf.put(&b"llo"[..]);

    assert_eq!(&buf[..], b"hello");

    // Freeze the buffer so that it can be shared
    let a = buf.freeze();

    // This does not allocate, instead `b` points to the same memory.
    let b = a.clone();

    assert_eq!(&a[..], b"hello");
    assert_eq!(&b[..], b"hello");

## Implementations

### `impl BytesMut` [src]

#### `pub fn with_capacity(capacity: usize) -> BytesMut` [src]

Creates a new `BytesMut` with the specified capacity.

The returned `BytesMut` will be able to hold at least `capacity` bytes without reallocating.

It is important to note that this function does not specify the length of the returned `BytesMut`, but only the capacity.

# Examples

    use bytes::{BytesMut, BufMut};

    let mut bytes = BytesMut::with_capacity(64);

    // `bytes` contains no data, even though there is capacity
    assert_eq!(bytes.len(), 0);

    bytes.put(&b"hello world"[..]);

    assert_eq!(&bytes[..], b"hello world");

#### `pub fn new() -> BytesMut` [src]

Creates a new `BytesMut` with default capacity.

Resulting object has length 0 and unspecified capacity. This function does not allocate.

# Examples

    use bytes::{BytesMut, BufMut};

    let mut bytes = BytesMut::new();

    assert_eq!(0, bytes.len());

    bytes.reserve(2);
    bytes.put_slice(b"xy");

    assert_eq!(&b"xy"[..], &bytes[..]);

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

Returns the number of bytes contained in this `BytesMut`.

# Examples

    use bytes::BytesMut;

    let b = BytesMut::from(&b"hello"[..]);
    assert_eq!(b.len(), 5);

#### `pub fn is_empty(&self) -> bool` [src]

Returns true if the `BytesMut` has a length of 0.

# Examples

    use bytes::BytesMut;

    let b = BytesMut::with_capacity(64);
    assert!(b.is_empty());

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

Returns the number of bytes the `BytesMut` can hold without reallocating.

# Examples

    use bytes::BytesMut;

    let b = BytesMut::with_capacity(64);
    assert_eq!(b.capacity(), 64);

#### `pub fn freeze(self) -> Bytes` [src]

Converts `self` into an immutable `Bytes`.

The conversion is zero cost and is used to indicate that the slice referenced by the handle will no longer be mutated. Once the conversion is done, the handle can be cloned and shared across threads.

# Examples

    use bytes::{BytesMut, BufMut};
    use std::thread;

    let mut b = BytesMut::with_capacity(64);
    b.put(&b"hello world"[..]);
    let b1 = b.freeze();
    let b2 = b1.clone();

    let th = thread::spawn(move || {
        assert_eq!(&b1[..], b"hello world");
    });

    assert_eq!(&b2[..], b"hello world");
    th.join().unwrap();

#### `#[must_use = "consider BytesMut::truncate if you don't need the other half"]pub fn split_off(&mut self, at: usize) -> BytesMut` [src]

Splits the bytes into two at the given index.

Afterwards `self` contains elements `[0, at)`, and the returned `BytesMut` contains elements `[at, capacity)`.

This is an `O(1)` operation that just increases the reference count and sets a few indices.

# Examples

    use bytes::BytesMut;

    let mut a = BytesMut::from(&b"hello world"[..]);
    let mut b = a.split_off(5);

    a[0] = b'j';
    b[0] = b'!';

    assert_eq!(&a[..], b"jello");
    assert_eq!(&b[..], b"!world");

# Panics

Panics if `at > capacity`.

#### `#[must_use = "consider BytesMut::advance(len()) if you don't need the other half"]pub fn split(&mut self) -> BytesMut` [src]

Removes the bytes from the current view, returning them in a new `BytesMut` handle.

Afterwards, `self` will be empty, but will retain any additional capacity that it had before the operation. This is identical to `self.split_to(self.len())`.

This is an `O(1)` operation that just increases the reference count and sets a few indices.

# Examples

    use bytes::{BytesMut, BufMut};

    let mut buf = BytesMut::with_capacity(1024);
    buf.put(&b"hello world"[..]);

    let other = buf.split();

    assert!(buf.is_empty());
    assert_eq!(1013, buf.capacity());

    assert_eq!(other, b"hello world"[..]);

#### `#[must_use = "consider BytesMut::advance if you don't need the other half"]pub fn split_to(&mut self, at: usize) -> BytesMut` [src]

Splits the buffer into two at the given index.

Afterwards `self` contains elements `[at, len)`, and the returned `BytesMut` contains elements `[0, at)`.

This is an `O(1)` operation that just increases the reference count and sets a few indices.

# Examples

    use bytes::BytesMut;

    let mut a = BytesMut::from(&b"hello world"[..]);
    let mut b = a.split_to(5);

    a[0] = b'!';
    b[0] = b'j';

    assert_eq!(&a[..], b"!world");
    assert_eq!(&b[..], b"jello");

# Panics

Panics if `at > len`.

#### `pub fn truncate(&mut self, len: usize)` [src]

Shortens the buffer, keeping the first `len` bytes and dropping the rest.

If `len` is greater than the buffer's current length, this has no effect.

The `split_off` method can emulate `truncate`, but this causes the excess bytes to be returned instead of dropped.

# Examples

    use bytes::BytesMut;

    let mut buf = BytesMut::from(&b"hello world"[..]);
    buf.truncate(5);
    assert_eq!(buf, b"hello"[..]);

#### `pub fn clear(&mut self)` [src]

Clears the buffer, removing all data.

# Examples

    use bytes::BytesMut;

    let mut buf = BytesMut::from(&b"hello world"[..]);
    buf.clear();
    assert!(buf.is_empty());

#### `pub fn resize(&mut self, new_len: usize, value: u8)` [src]

Resizes the buffer so that `len` is equal to `new_len`.

If `new_len` is greater than `len`, the buffer is extended by the difference with each additional byte set to `value`. If `new_len` is less than `len`, the buffer is simply truncated.

# Examples

    use bytes::BytesMut;

    let mut buf = BytesMut::new();

    buf.resize(3, 0x1);
    assert_eq!(&buf[..], &[0x1, 0x1, 0x1]);

    buf.resize(2, 0x2);
    assert_eq!(&buf[..], &[0x1, 0x1]);

    buf.resize(4, 0x3);
    assert_eq!(&buf[..], &[0x1, 0x1, 0x3, 0x3]);

#### `pub unsafe fn set_len(&mut self, len: usize)` [src]

Sets the length of the buffer.

This will explicitly set the size of the buffer without actually modifying the data, so it is up to the caller to ensure that the data has been initialized.

# Examples

    use bytes::BytesMut;

    let mut b = BytesMut::from(&b"hello world"[..]);

    unsafe {
        b.set_len(5);
    }

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

    unsafe {
        b.set_len(11);
    }

    assert_eq!(&b[..], b"hello world");

#### `pub fn reserve(&mut self, additional: usize)` [src]

Reserves capacity for at least `additional` more bytes to be inserted into the given `BytesMut`.

More than `additional` bytes may be reserved in order to avoid frequent reallocations. A call to `reserve` may result in an allocation.

Before allocating new buffer space, the function will attempt to reclaim space in the existing buffer. If the current handle references a small view in the original buffer and all other handles have been dropped, and the requested capacity is less than or equal to the existing buffer's capacity, then the current view will be copied to the front of the buffer and the handle will take ownership of the full buffer.

# Examples

In the following example, a new buffer is allocated.

    use bytes::BytesMut;

    let mut buf = BytesMut::from(&b"hello"[..]);
    buf.reserve(64);
    assert!(buf.capacity() >= 69);

In the following example, the existing buffer is reclaimed.

    use bytes::{BytesMut, BufMut};

    let mut buf = BytesMut::with_capacity(128);
    buf.put(&[0; 64][..]);

    let ptr = buf.as_ptr();
    let other = buf.split();

    assert!(buf.is_empty());
    assert_eq!(buf.capacity(), 64);

    drop(other);
    buf.reserve(128);

    assert_eq!(buf.capacity(), 128);
    assert_eq!(buf.as_ptr(), ptr);

# Panics

Panics if the new capacity overflows `usize`.

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

Appends given bytes to this `BytesMut`.

If this `BytesMut` object does not have enough capacity, it is resized first.

# Examples

    use bytes::BytesMut;

    let mut buf = BytesMut::with_capacity(0);
    buf.extend_from_slice(b"aaabbb");
    buf.extend_from_slice(b"cccddd");

    assert_eq!(b"aaabbbcccddd", &buf[..]);

#### `pub fn unsplit(&mut self, other: BytesMut)` [src]

Absorbs a `BytesMut` that was previously split off.

If the two `BytesMut` objects were previously contiguous, i.e., if `other` was created by calling `split_off` on this `BytesMut`, then this is an `O(1)` operation that just decreases a reference count and sets a few indices. Otherwise this method degenerates to `self.extend_from_slice(other.as_ref())`.

# Examples

    use bytes::BytesMut;

    let mut buf = BytesMut::with_capacity(64);
    buf.extend_from_slice(b"aaabbbcccddd");

    let split = buf.split_off(6);
    assert_eq!(b"aaabbb", &buf[..]);
    assert_eq!(b"cccddd", &split[..]);

    buf.unsplit(split);
    assert_eq!(b"aaabbbcccddd", &buf[..]);

## Trait Implementations

### `impl AsMut<[u8]> for BytesMut` [src]

#### `fn as_mut(&mut self) -> &mut [u8]` [src]

Performs the conversion.

### `impl AsRef<[u8]> for BytesMut` [src]

#### `fn as_ref(&self) -> &[u8]` [src]

Performs the conversion.

### `impl Borrow<[u8]> for BytesMut` [src]

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

Immutably borrows from an owned value. Read more

### `impl BorrowMut<[u8]> for BytesMut` [src]

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

Mutably borrows from an owned value. Read more

### `impl Buf for BytesMut` [src]

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

Returns the number of bytes between the current position and the end of the buffer. Read more

#### `fn chunk(&self) -> &[u8]` [src]

Returns a slice starting at the current position and of length between 0 and `Buf::remaining()`. Note that this can return shorter slice (this allows non-continuous internal representation). Read more

#### `fn advance(&mut self, cnt: usize)` [src]

Advance the internal cursor of the Buf Read more

#### `fn copy_to_bytes(&mut self, len: usize) -> Bytes` [src]

Consumes `len` bytes inside self and returns new instance of `Bytes` with this data. Read more

#### `fn chunks_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize` [src]

Fills `dst` with potentially multiple slices starting at `self`'s current position. Read more

#### `fn has_remaining(&self) -> bool` [src]

Returns true if there are any more bytes to consume Read more

#### `fn copy_to_slice(&mut self, dst: &mut [u8])` [src]

Copies bytes from `self` into `dst`. Read more

#### `fn get_u8(&mut self) -> u8` [src]

Gets an unsigned 8 bit integer from `self`. Read more

#### `fn get_i8(&mut self) -> i8` [src]

Gets a signed 8 bit integer from `self`. Read more

#### `fn get_u16(&mut self) -> u16` [src]

Gets an unsigned 16 bit integer from `self` in big-endian byte order. Read more

#### `fn get_u16_le(&mut self) -> u16` [src]

Gets an unsigned 16 bit integer from `self` in little-endian byte order. Read more

#### `fn get_i16(&mut self) -> i16` [src]

Gets a signed 16 bit integer from `self` in big-endian byte order. Read more

#### `fn get_i16_le(&mut self) -> i16` [src]

Gets a signed 16 bit integer from `self` in little-endian byte order. Read more

#### `fn get_u32(&mut self) -> u32` [src]

Gets an unsigned 32 bit integer from `self` in the big-endian byte order. Read more

#### `fn get_u32_le(&mut self) -> u32` [src]

Gets an unsigned 32 bit integer from `self` in the little-endian byte order. Read more

#### `fn get_i32(&mut self) -> i32` [src]

Gets a signed 32 bit integer from `self` in big-endian byte order. Read more

#### `fn get_i32_le(&mut self) -> i32` [src]

Gets a signed 32 bit integer from `self` in little-endian byte order. Read more

#### `fn get_u64(&mut self) -> u64` [src]

Gets an unsigned 64 bit integer from `self` in big-endian byte order. Read more

#### `fn get_u64_le(&mut self) -> u64` [src]

Gets an unsigned 64 bit integer from `self` in little-endian byte order. Read more

#### `fn get_i64(&mut self) -> i64` [src]

Gets a signed 64 bit integer from `self` in big-endian byte order. Read more

#### `fn get_i64_le(&mut self) -> i64` [src]

Gets a signed 64 bit integer from `self` in little-endian byte order. Read more

#### `fn get_u128(&mut self) -> u128` [src]

Gets an unsigned 128 bit integer from `self` in big-endian byte order. Read more

#### `fn get_u128_le(&mut self) -> u128` [src]

Gets an unsigned 128 bit integer from `self` in little-endian byte order. Read more

#### `fn get_i128(&mut self) -> i128` [src]

Gets a signed 128 bit integer from `self` in big-endian byte order. Read more

#### `fn get_i128_le(&mut self) -> i128` [src]

Gets a signed 128 bit integer from `self` in little-endian byte order. Read more

#### `fn get_uint(&mut self, nbytes: usize) -> u64` [src]

Gets an unsigned n-byte integer from `self` in big-endian byte order. Read more

#### `fn get_uint_le(&mut self, nbytes: usize) -> u64` [src]

Gets an unsigned n-byte integer from `self` in little-endian byte order. Read more

#### `fn get_int(&mut self, nbytes: usize) -> i64` [src]

Gets a signed n-byte integer from `self` in big-endian byte order. Read more

#### `fn get_int_le(&mut self, nbytes: usize) -> i64` [src]

Gets a signed n-byte integer from `self` in little-endian byte order. Read more

#### `fn get_f32(&mut self) -> f32` [src]

Gets an IEEE754 single-precision (4 bytes) floating point number from `self` in big-endian byte order. Read more

#### `fn get_f32_le(&mut self) -> f32` [src]

Gets an IEEE754 single-precision (4 bytes) floating point number from `self` in little-endian byte order. Read more

#### `fn get_f64(&mut self) -> f64` [src]

Gets an IEEE754 double-precision (8 bytes) floating point number from `self` in big-endian byte order. Read more

#### `fn get_f64_le(&mut self) -> f64` [src]

Gets an IEEE754 double-precision (8 bytes) floating point number from `self` in little-endian byte order. Read more

#### `fn take(self, limit: usize) -> Take<Self> where
Self: Sized,` [src]

Creates an adaptor which will read at most `limit` bytes from `self`. Read more

#### `fn chain<U: Buf>(self, next: U) -> Chain<Self, U> where
Self: Sized,` [src]

Creates an adaptor which will chain this buffer with another. Read more

#### `fn reader(self) -> Reader<Self>ⓘ

### Notable traits for Reader<B>

`impl<B: Buf + Sized> Read for Reader<B>`
where
Self: Sized,` [src]

Creates an adaptor which implements the `Read` trait for `self`. Read more

### `impl BufMut for BytesMut` [src]

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

Returns the number of bytes that can be written from the current position until the end of the buffer is reached. Read more

#### `unsafe fn advance_mut(&mut self, cnt: usize)` [src]

Advance the internal cursor of the BufMut Read more

#### `fn chunk_mut(&mut self) -> &mut UninitSlice` [src]

Returns a mutable slice starting at the current BufMut position and of length between 0 and `BufMut::remaining_mut()`. Note that this can be shorter than the whole remainder of the buffer (this allows non-continuous implementation). Read more

#### `fn put<T: Buf>(&mut self, src: T) where
Self: Sized,` [src]

Transfer bytes into `self` from `src` and advance the cursor by the number of bytes written. Read more

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

Transfer bytes into `self` from `src` and advance the cursor by the number of bytes written. Read more

#### `fn has_remaining_mut(&self) -> bool` [src]

Returns true if there is space in `self` for more bytes. Read more

#### `fn put_u8(&mut self, n: u8)` [src]

Writes an unsigned 8 bit integer to `self`. Read more

#### `fn put_i8(&mut self, n: i8)` [src]

Writes a signed 8 bit integer to `self`. Read more

#### `fn put_u16(&mut self, n: u16)` [src]

Writes an unsigned 16 bit integer to `self` in big-endian byte order. Read more

#### `fn put_u16_le(&mut self, n: u16)` [src]

Writes an unsigned 16 bit integer to `self` in little-endian byte order. Read more

#### `fn put_i16(&mut self, n: i16)` [src]

Writes a signed 16 bit integer to `self` in big-endian byte order. Read more

#### `fn put_i16_le(&mut self, n: i16)` [src]

Writes a signed 16 bit integer to `self` in little-endian byte order. Read more

#### `fn put_u32(&mut self, n: u32)` [src]

Writes an unsigned 32 bit integer to `self` in big-endian byte order. Read more

#### `fn put_u32_le(&mut self, n: u32)` [src]

Writes an unsigned 32 bit integer to `self` in little-endian byte order. Read more

#### `fn put_i32(&mut self, n: i32)` [src]

Writes a signed 32 bit integer to `self` in big-endian byte order. Read more

#### `fn put_i32_le(&mut self, n: i32)` [src]

Writes a signed 32 bit integer to `self` in little-endian byte order. Read more

#### `fn put_u64(&mut self, n: u64)` [src]

Writes an unsigned 64 bit integer to `self` in the big-endian byte order. Read more

#### `fn put_u64_le(&mut self, n: u64)` [src]

Writes an unsigned 64 bit integer to `self` in little-endian byte order. Read more

#### `fn put_i64(&mut self, n: i64)` [src]

Writes a signed 64 bit integer to `self` in the big-endian byte order. Read more

#### `fn put_i64_le(&mut self, n: i64)` [src]

Writes a signed 64 bit integer to `self` in little-endian byte order. Read more

#### `fn put_u128(&mut self, n: u128)` [src]

Writes an unsigned 128 bit integer to `self` in the big-endian byte order. Read more

#### `fn put_u128_le(&mut self, n: u128)` [src]

Writes an unsigned 128 bit integer to `self` in little-endian byte order. Read more

#### `fn put_i128(&mut self, n: i128)` [src]

Writes a signed 128 bit integer to `self` in the big-endian byte order. Read more

#### `fn put_i128_le(&mut self, n: i128)` [src]

Writes a signed 128 bit integer to `self` in little-endian byte order. Read more

#### `fn put_uint(&mut self, n: u64, nbytes: usize)` [src]

Writes an unsigned n-byte integer to `self` in big-endian byte order. Read more

#### `fn put_uint_le(&mut self, n: u64, nbytes: usize)` [src]

Writes an unsigned n-byte integer to `self` in the little-endian byte order. Read more

#### `fn put_int(&mut self, n: i64, nbytes: usize)` [src]

Writes a signed n-byte integer to `self` in big-endian byte order. Read more

#### `fn put_int_le(&mut self, n: i64, nbytes: usize)` [src]

Writes a signed n-byte integer to `self` in little-endian byte order. Read more

#### `fn put_f32(&mut self, n: f32)` [src]

Writes an IEEE754 single-precision (4 bytes) floating point number to `self` in big-endian byte order. Read more

#### `fn put_f32_le(&mut self, n: f32)` [src]

Writes an IEEE754 single-precision (4 bytes) floating point number to `self` in little-endian byte order. Read more

#### `fn put_f64(&mut self, n: f64)` [src]

Writes an IEEE754 double-precision (8 bytes) floating point number to `self` in big-endian byte order. Read more

#### `fn put_f64_le(&mut self, n: f64)` [src]

Writes an IEEE754 double-precision (8 bytes) floating point number to `self` in little-endian byte order. Read more

#### `fn limit(self, limit: usize) -> Limit<Self> where
Self: Sized,` [src]

Creates an adaptor which can write at most `limit` bytes to `self`. Read more

#### `fn writer(self) -> Writer<Self>ⓘ

### Notable traits for Writer<B>

`impl<B: BufMut + Sized> Write for Writer<B>`
where
Self: Sized,` [src]

Creates an adaptor which implements the `Write` trait for `self`. Read more

#### `fn chain_mut<U: BufMut>(self, next: U) -> Chain<Self, U> where
Self: Sized,` [src]

Creates an adapter which will chain this buffer with another. Read more

### `impl Clone for BytesMut` [src]

#### `fn clone(&self) -> BytesMut` [src]

Returns a copy of the value. Read more

#### `pub fn clone_from(&mut self, source: &Self)`1.0.0 [src]

Performs copy-assignment from `source`. Read more

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

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

Formats the value using the given formatter. Read more

### `impl Default for BytesMut` [src]

#### `fn default() -> BytesMut` [src]

Returns the "default value" for a type. Read more

### `impl Deref for BytesMut` [src]

#### `type Target = [u8]`

The resulting type after dereferencing.

#### `fn deref(&self) -> &[u8]` [src]

Dereferences the value.

### `impl DerefMut for BytesMut` [src]

#### `fn deref_mut(&mut self) -> &mut [u8]` [src]

Mutably dereferences the value.

### `impl Drop for BytesMut` [src]

#### `fn drop(&mut self)` [src]

Executes the destructor for this type. Read more

### `impl Eq for BytesMut` [src]

### `impl<'a> Extend<&'a u8> for BytesMut` [src]

#### `fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = &'a u8>,` [src]

Extends a collection with the contents of an iterator. Read more

#### `pub fn extend_one(&mut self, item: A)` [src]

🔬 This is a nightly-only experimental API. (`extend_one`)

Extends a collection with exactly one element.

#### `pub fn extend_reserve(&mut self, additional: usize)` [src]

🔬 This is a nightly-only experimental API. (`extend_one`)

Reserves capacity in a collection for the given number of additional elements. Read more

### `impl Extend<u8> for BytesMut` [src]

#### `fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = u8>,` [src]

Extends a collection with the contents of an iterator. Read more

#### `pub fn extend_one(&mut self, item: A)` [src]

🔬 This is a nightly-only experimental API. (`extend_one`)

Extends a collection with exactly one element.

#### `pub fn extend_reserve(&mut self, additional: usize)` [src]

🔬 This is a nightly-only experimental API. (`extend_one`)

Reserves capacity in a collection for the given number of additional elements. Read more

### `impl<'a> From<&'a [u8]> for BytesMut` [src]

#### `fn from(src: &'a [u8]) -> BytesMut` [src]

Performs the conversion.

### `impl<'a> From<&'a str> for BytesMut` [src]

#### `fn from(src: &'a str) -> BytesMut` [src]

Performs the conversion.

### `impl From<BytesMut> for Bytes` [src]

#### `fn from(src: BytesMut) -> Bytes` [src]

Performs the conversion.

### `impl<'a> FromIterator<&'a u8> for BytesMut` [src]

#### `fn from_iter<T: IntoIterator<Item = &'a u8>>(into_iter: T) -> Self` [src]

Creates a value from an iterator. Read more

### `impl FromIterator<u8> for BytesMut` [src]

#### `fn from_iter<T: IntoIterator<Item = u8>>(into_iter: T) -> Self` [src]

Creates a value from an iterator. Read more

### `impl Hash for BytesMut` [src]

#### `fn hash<H>(&self, state: &mut H) where
H: Hasher,` [src]

Feeds this value into the given `Hasher`. Read more

#### `pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,` 1.3.0 [src]

Feeds a slice of this type into the given `Hasher`. Read more

### `impl IntoIterator for BytesMut` [src]

#### `type Item = u8`

The type of the elements being iterated over.

#### `type IntoIter = IntoIter<BytesMut>`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> Self::IntoIter` [src]

Creates an iterator from a value. Read more

### `impl<'a> IntoIterator for &'a BytesMut` [src]

#### `type Item = &'a u8`

The type of the elements being iterated over.

#### `type IntoIter = Iter<'a, u8>`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> Self::IntoIter` [src]

Creates an iterator from a value. Read more

### `impl LowerHex for BytesMut` [src]

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

Formats the value using the given formatter.

### `impl Ord for BytesMut` [src]

#### `fn cmp(&self, other: &BytesMut) -> Ordering` [src]

This method returns an `Ordering` between `self` and `other`. Read more

#### `#[must_use]pub fn max(self, other: Self) -> Self` 1.21.0 [src]

Compares and returns the maximum of two values. Read more

#### `#[must_use]pub fn min(self, other: Self) -> Self` 1.21.0 [src]

Compares and returns the minimum of two values. Read more

#### `#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self` 1.50.0 [src]

Restrict a value to a certain interval. Read more

### `impl<'a, T: ?Sized> PartialEq<&'a T> for BytesMut where
BytesMut: PartialEq<T>,` [src]

#### `fn eq(&self, other: &&'a T) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<[u8]> for BytesMut` [src]

#### `fn eq(&self, other: &[u8]) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<Bytes> for BytesMut` [src]

#### `fn eq(&self, other: &Bytes) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<BytesMut> for BytesMut` [src]

#### `fn eq(&self, other: &BytesMut) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<BytesMut> for [u8]` [src]

#### `fn eq(&self, other: &BytesMut) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<BytesMut> for str` [src]

#### `fn eq(&self, other: &BytesMut) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<BytesMut> for Vec<u8>` [src]

#### `fn eq(&self, other: &BytesMut) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<BytesMut> for String` [src]

#### `fn eq(&self, other: &BytesMut) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<BytesMut> for &[u8]` [src]

#### `fn eq(&self, other: &BytesMut) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<BytesMut> for &str` [src]

#### `fn eq(&self, other: &BytesMut) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<BytesMut> for Bytes` [src]

#### `fn eq(&self, other: &BytesMut) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<String> for BytesMut` [src]

#### `fn eq(&self, other: &String) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<Vec<u8, Global>> for BytesMut` [src]

#### `fn eq(&self, other: &Vec<u8>) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl PartialEq<str> for BytesMut` [src]

#### `fn eq(&self, other: &str) -> bool` [src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use]pub fn ne(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests for `!=`.

### `impl<'a, T: ?Sized> PartialOrd<&'a T> for BytesMut where
BytesMut: PartialOrd<T>,` [src]

#### `fn partial_cmp(&self, other: &&'a T) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<[u8]> for BytesMut` [src]

#### `fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<BytesMut> for BytesMut` [src]

#### `fn partial_cmp(&self, other: &BytesMut) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<BytesMut> for [u8]` [src]

#### `fn partial_cmp(&self, other: &BytesMut) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<BytesMut> for str` [src]

#### `fn partial_cmp(&self, other: &BytesMut) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<BytesMut> for Vec<u8>` [src]

#### `fn partial_cmp(&self, other: &BytesMut) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<BytesMut> for String` [src]

#### `fn partial_cmp(&self, other: &BytesMut) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<BytesMut> for &[u8]` [src]

#### `fn partial_cmp(&self, other: &BytesMut) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<BytesMut> for &str` [src]

#### `fn partial_cmp(&self, other: &BytesMut) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<String> for BytesMut` [src]

#### `fn partial_cmp(&self, other: &String) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<Vec<u8, Global>> for BytesMut` [src]

#### `fn partial_cmp(&self, other: &Vec<u8>) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl PartialOrd<str> for BytesMut` [src]

#### `fn partial_cmp(&self, other: &str) -> Option<Ordering>` [src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `#[must_use]pub fn lt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `#[must_use]pub fn le(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `#[must_use]pub fn gt(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `#[must_use]pub fn ge(&self, other: &Rhs) -> bool` 1.0.0 [src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. Read more

### `impl Send for BytesMut` [src]

### `impl Sync for BytesMut` [src]

### `impl UpperHex for BytesMut` [src]

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

Formats the value using the given formatter.

### `impl Write for BytesMut` [src]

#### `fn write_str(&mut self, s: &str) -> Result` [src]

Writes a string slice into this writer, returning whether the write succeeded. Read more

#### `fn write_fmt(&mut self, args: Arguments<'_>) -> Result` [src]

Glue for usage of the `write!` macro with implementors of this trait. Read more

#### `pub fn write_char(&mut self, c: char) -> Result<(), Error>`1.1.0 [src]

Writes a `char` into this writer, returning whether the write succeeded. Read more

## Auto Trait Implementations

### `impl RefUnwindSafe for BytesMut` [src]

### `impl Unpin for BytesMut` [src]

### `impl UnwindSafe for BytesMut` [src]

## 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

### `impl<T> From<T> for T` [src]

#### `pub fn from(t: T) -> T` [src]

Performs the conversion.

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `pub fn into(self) -> U` [src]

Performs the conversion.

### `impl<T> ToOwned for T where
T: Clone,` [src]

#### `type Owned = T`

The resulting type after obtaining ownership.

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

Creates owned data from borrowed data, usually by cloning. Read more

#### `pub fn clone_into(&self, target: &mut T)` [src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>` [src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>` [src]

Performs the conversion.