Taylor Bockman 7 years ago
parent
commit
42f366b2aa
  1. 13
      src/lib.rs

13
src/lib.rs

@ -4,11 +4,14 @@
mod commands;
use std::fmt;
#[derive(Debug)]
pub struct Engine<'a, R, W> {
pub name: &'a str,
pub author: &'a str,
pub mut reader: R,
pub mut writer: W,
pub reader: R,
pub writer: W,
}
/// 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
/// TODO: Write tests for this. Reference:
/// https://stackoverflow.com/questions/28370126/how-can-i-test-stdin-and-stdout
pub fn identify(&self) {
let name_id: String = fmt!("{} {} {}", constants::ID, constants::NAME, self.name);
let author_id: String = fmt!("{} {} {}", constants::ID, constants::AUTHOR, self.author);
pub fn identify(&mut self) {
let name_id: String = format!("{} {} {}", commands::ID, commands::NAME, self.name);
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
write!(&mut self.writer, "{}", name_id).expect("failed to send name identification to writer");

Loading…
Cancel
Save