to vector of bytes because maybe thats better for avro
parent
a293297d6e
commit
1c8c399aaa
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::config::Engine;
|
use crate::config::Engine;
|
||||||
|
|
||||||
pub trait InputEngine {
|
pub trait InputEngine {
|
||||||
fn get(&self) -> String;
|
fn get(&self) -> Vec<char>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_input_engine(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
pub fn build_input_engine(cfg: &Engine) -> Result<Box<dyn InputEngine>, String> {
|
||||||
|
|
@ -14,11 +14,11 @@ pub fn build_input_engine(cfg: &Engine) -> Result<Box<dyn InputEngine>, String>
|
||||||
struct InputEngineStdin {}
|
struct InputEngineStdin {}
|
||||||
|
|
||||||
impl InputEngine for InputEngineStdin {
|
impl InputEngine for InputEngineStdin {
|
||||||
fn get(&self) -> String {
|
fn get(&self) -> Vec<char> {
|
||||||
let stdin = std::io::stdin();
|
let stdin = std::io::stdin();
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
stdin.read_line(&mut result).unwrap();
|
stdin.read_line(&mut result).unwrap();
|
||||||
return result.trim().to_string();
|
return result.trim().chars().collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,8 +28,8 @@ mod test_input {
|
||||||
|
|
||||||
struct InputEngineTest {}
|
struct InputEngineTest {}
|
||||||
impl InputEngine for InputEngineTest {
|
impl InputEngine for InputEngineTest {
|
||||||
fn get(&self) -> String {
|
fn get(&self) -> Vec<char> {
|
||||||
return "hello world".to_string();
|
return "hello world".chars().collect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,12 +40,12 @@ mod test_input {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _test_input_engine_impl(engine: &dyn InputEngine) {
|
fn _test_input_engine_impl(engine: &dyn InputEngine) {
|
||||||
assert_eq!("hello world".to_string(), engine.get());
|
assert_eq!("hello world".to_string(), engine.get().iter().cloned().collect::<String>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait OutputEngine {
|
pub trait OutputEngine {
|
||||||
fn put(&self, v: String);
|
fn put(&self, v: Vec<char>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_output_engine(cfg: &Engine) -> Result<Box<dyn OutputEngine>, String> {
|
pub fn build_output_engine(cfg: &Engine) -> Result<Box<dyn OutputEngine>, String> {
|
||||||
|
|
@ -58,8 +58,8 @@ pub fn build_output_engine(cfg: &Engine) -> Result<Box<dyn OutputEngine>, String
|
||||||
struct OutputEngineStdout {}
|
struct OutputEngineStdout {}
|
||||||
|
|
||||||
impl OutputEngine for OutputEngineStdout {
|
impl OutputEngine for OutputEngineStdout {
|
||||||
fn put(&self, v: String) {
|
fn put(&self, v: Vec<char>) {
|
||||||
println!("{}", v);
|
println!("{}", v.iter().cloned().collect::<String>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +69,7 @@ mod test_output {
|
||||||
|
|
||||||
struct OutputEngineTest {}
|
struct OutputEngineTest {}
|
||||||
impl OutputEngine for OutputEngineTest {
|
impl OutputEngine for OutputEngineTest {
|
||||||
fn put(&self, _v: String) {
|
fn put(&self, _v: Vec<char>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,6 +80,6 @@ mod test_output {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _test_output_engine_impl(engine: &dyn OutputEngine) {
|
fn _test_output_engine_impl(engine: &dyn OutputEngine) {
|
||||||
engine.put("teehee".to_string());
|
engine.put("teehee".to_string().chars().collect());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue