Ajout : module io, modification des use

This commit is contained in:
Hippolyte Chauvin 2023-11-01 13:34:33 +01:00
parent f4fb13c96e
commit c972102a38
2 changed files with 14 additions and 5 deletions

3
src/io.rs Normal file
View file

@ -0,0 +1,3 @@
pub fn run() -> i32 {
todo!();
}

View file

@ -1,21 +1,27 @@
use std::io; use std::io as stdio;
use std::io::Write; use stdio::{
stdin,
stdout,
Write,
};
use std::process::exit;
mod parser; mod parser;
mod io;
fn main() { fn main() {
let mut buffer = String::new(); let mut buffer = String::new();
let mut bytes_read_result: io::Result<usize>; let mut bytes_read_result: stdio::Result<usize>;
let mut bytes_read: usize = 1; let mut bytes_read: usize = 1;
while bytes_read != 0 { while bytes_read != 0 {
buffer.clear(); buffer.clear();
print!("$ "); print!("$ ");
if io::stdout().flush().is_err() { if stdout().flush().is_err() {
eprintln!("error: can't fully flush stdout or reached EOF"); eprintln!("error: can't fully flush stdout or reached EOF");
} }
bytes_read_result = io::stdin().read_line(&mut buffer); bytes_read_result = stdin().read_line(&mut buffer);
if bytes_read_result.is_err() { if bytes_read_result.is_err() {
eprintln!("error: invalid UTF-8 characters were read"); eprintln!("error: invalid UTF-8 characters were read");