Slices

We just need one more concept before we're ready to move on with our fuzz target: slices!

A slice is just a reference to a sequence of items with the same type. They can be created literally, as with this creation of a slice referencing the sequence of two strings:

fn main() {
    let _x: &[String] = &[
        "Hello, World!".to_string(),
        "I'm here!".to_string()
    ];
}
Playground

They can also be created by referencing another data structure. For example a slice of a Vec (equivalent to a C++ std::vector) is a reference to a sequence of its entries. We can also take a slice of a String's characters as a sequence of bytes using .as_bytes(). Slices are very flexible, and many methods of various types yield slices of different underlying element types (such as as_bytes()).

fn main() {
    let v: Vec<String> = vec![
        "Hello, World!".to_string(),
        "I'm here!".to_string()
    ];
    let _x: &[String] = &v;
    let u: String = "Hello, World!".to_string();
    let _y: &[u8] = u.as_bytes();
}
Playground