rustRust bytes buffer example
Rust provides a Vec<u8>
type to represent a buffer of bytes. This type is a growable array of bytes, and can be used to store data such as images, audio, and text.
let mut buffer = Vec::new();
buffer.push(0x41);
buffer.push(0x42);
buffer.push(0x43);
The above code creates a Vec<u8>
buffer and adds three bytes to it (0x41, 0x42, and 0x43).
let mut buffer = Vec::new();
creates a new emptyVec<u8>
buffer.buffer.push(0x41);
adds the byte 0x41 to the end of the buffer.buffer.push(0x42);
adds the byte 0x42 to the end of the buffer.buffer.push(0x43);
adds the byte 0x43 to the end of the buffer.
The output of the above code is a Vec<u8>
buffer containing the bytes 0x41, 0x42, and 0x43.
Helpful links
Related
More of Rust
- How to create a slice from a string in Rust?
- How do I declare a variable with a type in Rust?
- How to match digits with regex in Rust?
- How to use captures_iter with regex in Rust?
- How to convert a u8 slice to a hex string in Rust?
- How to convert Rust bytes to hex?
- How to use regex to match a double quote in Rust?
- How to use the global flag in a Rust regex?
- How to use regex with bytes in Rust?
- How to calculate the inverse of a matrix in Rust?
See more codes...