read_vectored 方法 in rust

main.rs
// Define a struct with vectors
struct MyStruct {
    vector1: Vec<i32>,
    vector2: Vec<String>,
}

impl MyStruct {
    // Define a method to read vectors
    fn read_vectored(&self) {
        println!("{:?}", self.vector1);
        println!("{:?}", self.vector2);
    }
}

fn main() {
    let obj = MyStruct {
        vector1: vec![1, 2, 3],
        vector2: vec!["a".to_string(), "b".to_string()],
    };
    
    obj.read_vectored();
}
441 chars
23 lines

This Rust code shows how to define a struct with vectors and a method called read_vectored that prints out the values of the vectors.

related categories

gistlibby LogSnag