From 9022d04ca9b64b41e0d1fbc00912fbd9adf37255 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Sun, 10 Dec 2023 20:57:54 +0100 Subject: [PATCH] =?UTF-8?q?Moins=20de=20lignes=20dans=20`main.rs`,=20d?= =?UTF-8?q?=C3=A9l=C3=A9gation=20de=20l'appel=20de=20`parse`=20=C3=A0=20`s?= =?UTF-8?q?truct=20Buffer`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/input.rs | 13 +++++++------ src/main.rs | 10 ++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/input.rs b/src/input.rs index 849dd68..93ac102 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,5 +1,6 @@ use std::io as stdio; use stdio::stdin; +use crate::parser; pub struct Buffer { buffer: String, @@ -27,11 +28,11 @@ impl Buffer { } } - pub fn is_empty(&self) -> bool { - self.buffer.is_empty() - } - - pub fn get_buffer(&self) -> &String { - &self.buffer + pub fn parse(&self) -> Option> { + if ! self.buffer.is_empty() { + Some(parser::parse(&self.buffer)) + } else { + None + } } } diff --git a/src/main.rs b/src/main.rs index a30723d..8458530 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,17 +7,15 @@ mod parser; fn main() { let mut buffer = input::Buffer::new(); let mut bytes_read: usize = 1; - let mut command_line: String; - let mut argv: Vec; + let mut argv: Option>; while bytes_read != 0 { output::print_ps1(); bytes_read = buffer.read_line(); - if ! buffer.is_empty() { - command_line = buffer.get_buffer().to_string(); - argv = parser::parse(&command_line); - println!("{:?}", argv); + argv = buffer.parse(); + if argv.is_some() { + println!("{:?}", argv.unwrap()); } }