A vector of bytes.
Methods
Construct a byte array with the given preallocated capacity.
Examples
let bytes = with_capacity;
assert_eq!;
bytes.extend;
assert_eq!;
Convert a byte array into bytes.
Examples
let bytes = from_vec;
assert_eq!;
Convert the byte array into a vector of bytes.
Examples
let bytes = b"abcd";
assert_eq!;
assert!;
Convert the byte array into a vector of bytes without consuming it.
Examples
let bytes = b"abcd";
assert_eq!;
assert!;
Extend these bytes with another collection of bytes.
Examples
let bytes = b"abcd";
bytes.extend;
assert_eq!;
Extend this bytes collection with a string.
Examples
let bytes = b"abcd";
bytes.extend_str;
assert_eq!;
Get the length of the bytes collection.
Examples
let bytes = new;
assert_eq!;
bytes.extend;
assert_eq!;
Returns the total number of elements the vector can hold without reallocating.
Examples
let bytes = with_capacity;
bytes.extend;
assert!;
Clears the vector, removing all values.
Note that this method has no effect on the allocated capacity of the vector.
Examples
let bytes = b"abc";
bytes.clear;
assert!;
Reserves capacity for at least additional
more elements to be inserted in the given Bytes
. The collection may reserve more space to speculatively avoid frequent reallocations. After calling reserve
, capacity will be greater than or equal to self.len() + additional
. Does nothing if capacity is already sufficient.
Panics
Panics if the new capacity exceeds isize::MAX
bytes.
Examples
let vec = b"a";
vec.reserve;
assert!;
Reserves the minimum capacity for at least additional
more elements to be inserted in the given Bytes
. Unlike reserve
, this will not deliberately over-allocate to speculatively avoid frequent allocations. After calling reserve_exact
, capacity will be greater than or equal to self.len() + additional
. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer reserve
if future insertions are expected.
Panics
Panics if the new capacity exceeds isize::MAX
bytes.
Examples
let vec = b"a";
vec.reserve_exact;
assert!;
Clone the byte array.
Examples
let a = b"hello world";
let b = a.clone;
a.extend;
assert_eq!;
assert_eq!;
Shrinks the capacity of the byte array as much as possible.
It will drop down as close as possible to the length but the allocator may still inform the byte array that there is space for a few more elements.
Examples
let bytes = with_capacity;
bytes.extend;
assert!;
bytes.shrink_to_fit;
assert!;