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!;
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!;
Trait Implementations
Clone the specified value
.
Examples
let a = 42;
let b = a;
let c = a.clone;
a += 1;
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values for equality.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values for inequality.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values.
Examples
use Ordering;
assert_eq!;
assert_eq!;
assert_eq!;
Tests less than (for self
and other
) and is used by the <
operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests less than or equal to (for self
and other
) and is used by the <=
operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests greater than (for self
and other
) and is used by the >
operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Tests greater than or equal to (for self
and other
) and is used by the >=
operator.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Compare two values.
Examples
use Ordering;
assert_eq!;
assert_eq!;
assert_eq!;
Return the minimum of two values.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Return the maximum of two values.
Examples
assert_eq!;
assert_eq!;
assert_eq!;
Protocols
let $out = clone
Clone the byte array.
Examples
let a = b"hello world";
let b = a.clone;
a.extend;
assert_eq!;
assert_eq!;
if value == b
Test two byte arrays for partial equality.
Examples
use partial_eq;
assert_eq!;
assert_eq!;
assert_eq!;
if value == b
Test two byte arrays for total equality.
Examples
use eq;
assert_eq!;
assert_eq!;
assert_eq!;
if value < b
Perform a partial ordered comparison between two byte arrays.
Examples
assert!;
assert!;
assert!;
Using explicit functions:
use Ordering;
use partial_cmp;
assert_eq!;
assert_eq!;
assert_eq!;
if value < b
Perform a totally ordered comparison between two byte arrays.
Examples
use Ordering;
use cmp;
assert_eq!;
assert_eq!;
assert_eq!;
let $out = hash
Hash the byte array.
Examples
use hash;
let a = "hello";
let b = "hello";
assert_eq!;