|
|
@ -4,11 +4,14 @@ |
|
|
|
|
|
|
|
|
|
|
|
mod commands; |
|
|
|
mod commands; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::fmt; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
pub struct Engine<'a, R, W> { |
|
|
|
pub struct Engine<'a, R, W> { |
|
|
|
pub name: &'a str, |
|
|
|
pub name: &'a str, |
|
|
|
pub author: &'a str, |
|
|
|
pub author: &'a str, |
|
|
|
pub mut reader: R, |
|
|
|
pub reader: R, |
|
|
|
pub mut writer: W, |
|
|
|
pub writer: W, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Notes to delete later:
|
|
|
|
/// Notes to delete later:
|
|
|
@ -42,9 +45,9 @@ impl<'a> Engine<'a, R, W> { |
|
|
|
/// Sends identification messages to the writer for the GUI to pick up
|
|
|
|
/// Sends identification messages to the writer for the GUI to pick up
|
|
|
|
/// TODO: Write tests for this. Reference:
|
|
|
|
/// TODO: Write tests for this. Reference:
|
|
|
|
/// https://stackoverflow.com/questions/28370126/how-can-i-test-stdin-and-stdout
|
|
|
|
/// https://stackoverflow.com/questions/28370126/how-can-i-test-stdin-and-stdout
|
|
|
|
pub fn identify(&self) { |
|
|
|
pub fn identify(&mut self) { |
|
|
|
let name_id: String = fmt!("{} {} {}", constants::ID, constants::NAME, self.name); |
|
|
|
let name_id: String = format!("{} {} {}", commands::ID, commands::NAME, self.name); |
|
|
|
let author_id: String = fmt!("{} {} {}", constants::ID, constants::AUTHOR, self.author); |
|
|
|
let author_id: String = format!("{} {} {}", commands::ID, commands::AUTHOR, self.author); |
|
|
|
|
|
|
|
|
|
|
|
// For these two writes we can panic - there's no possibility of recovery if the engine fails at this stage
|
|
|
|
// For these two writes we can panic - there's no possibility of recovery if the engine fails at this stage
|
|
|
|
write!(&mut self.writer, "{}", name_id).expect("failed to send name identification to writer"); |
|
|
|
write!(&mut self.writer, "{}", name_id).expect("failed to send name identification to writer"); |
|
|
|