extending structs

This commit is contained in:
Maddie 2022-11-03 08:47:26 +00:00 committed by GitHub
parent ca0938b523
commit 70678df036
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,20 +1,32 @@
struct Buffer { enum Mode {
Normal,
Insert,
Select
}
struct Buffer<'a> {
data: Vec<String>, data: Vec<String>,
name: &str, name: &'a str,
path: &'a str,
} }
struct Editor { struct Editor {
buffer: Buffer, buffer: Buffer,
cursor: [i32, 2],
mode: Mode;
} }
fn main() { fn main() {
let bufffer = Buffer { let bufffer = Buffer {
data: Vec::from([String::from("a test")]), data: Vec::from([String::from("Hello"), String::from("World")]),
name: "uhh" name: "[No Name]",
path: "/home/spy",
}; };
let editor = Editor { let editor = Editor {
buffer: bufffer, buffer: bufffer,
cursor: [0, 0],
mode: Mode::Normal,
}; };
println!("{}", editor.buffer.data[0]) println!("{}", editor.buffer.data[0])