From be73db13e0289314faaff134cc17c8c9b179ae34 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Wed, 13 Feb 2019 11:45:41 -0700 Subject: [PATCH] Improve EntryStream trait and struct names --- src/entry_stream.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/entry_stream.rs b/src/entry_stream.rs index 32edb79329..31086ab2ca 100644 --- a/src/entry_stream.rs +++ b/src/entry_stream.rs @@ -14,25 +14,25 @@ use std::os::unix::net::UnixStream; use std::path::Path; use std::sync::{Arc, RwLock}; -pub trait Output: std::fmt::Debug { +pub trait EntryWriter: std::fmt::Debug { fn write(&self, payload: String) -> Result<()>; } #[derive(Debug, Default)] -pub struct VecOutput { +pub struct EntryVec { values: RefCell>, } -impl Output for VecOutput { +impl EntryWriter for EntryVec { fn write(&self, payload: String) -> Result<()> { self.values.borrow_mut().push(payload); Ok(()) } } -impl VecOutput { +impl EntryVec { pub fn new() -> Self { - VecOutput { + EntryVec { values: RefCell::new(Vec::new()), } } @@ -43,11 +43,11 @@ impl VecOutput { } #[derive(Debug)] -pub struct SocketOutput { +pub struct EntrySocket { socket: String, } -impl Output for SocketOutput { +impl EntryWriter for EntrySocket { fn write(&self, payload: String) -> Result<()> { let mut socket = UnixStream::connect(Path::new(&self.socket))?; socket.write_all(payload.as_bytes())?; @@ -68,7 +68,7 @@ pub trait EntryStreamHandler { } #[derive(Debug)] -pub struct EntryStream { +pub struct EntryStream { pub output: T, pub leader_scheduler: Arc>, pub queued_block: Option, @@ -76,7 +76,7 @@ pub struct EntryStream { impl EntryStreamHandler for EntryStream where - T: Output, + T: EntryWriter, { fn emit_entry_event(&self, slot: u64, leader_id: &str, entry: &Entry) -> Result<()> { let json_entry = serde_json::to_string(&entry)?; @@ -111,24 +111,24 @@ where } } -pub type SocketEntryStream = EntryStream; +pub type SocketEntryStream = EntryStream; impl SocketEntryStream { pub fn new(socket: String, leader_scheduler: Arc>) -> Self { EntryStream { - output: SocketOutput { socket }, + output: EntrySocket { socket }, leader_scheduler, queued_block: None, } } } -pub type MockEntryStream = EntryStream; +pub type MockEntryStream = EntryStream; impl MockEntryStream { pub fn new(_: String, leader_scheduler: Arc>) -> Self { EntryStream { - output: VecOutput::new(), + output: EntryVec::new(), leader_scheduler, queued_block: None, }