Implement From<&str> for Program

This commit is contained in:
Lewis Dale 2023-01-04 09:00:27 +00:00
parent 83bf4b3bac
commit dd6a64539a
2 changed files with 8 additions and 1 deletions

View File

@ -96,6 +96,13 @@ impl Program {
}
}
impl From<&str> for Program {
fn from(value: &str) -> Self {
let (_, program) = read_program(value).unwrap();
program
}
}
impl Iterator for Program {
type Item = Node;

View File

@ -4,6 +4,6 @@ mod basic;
fn main() {
let file = fs::read_to_string("./inputs/simple_program.bas").unwrap();
let (_, mut program) = basic::read_program(&file).unwrap();
let mut program = basic::Program::from(file.as_str());
program.execute();
}