Skip to content

Commit

Permalink
Improve EntryStream trait and struct names
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Feb 13, 2019
1 parent ec076eb commit ba17616
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/entry_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
}

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()),
}
}
Expand All @@ -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())?;
Expand All @@ -68,15 +68,15 @@ pub trait EntryStreamHandler {
}

#[derive(Debug)]
pub struct EntryStream<T: Output> {
pub struct EntryStream<T: EntryWriter> {
pub output: T,
pub leader_scheduler: Arc<RwLock<LeaderScheduler>>,
pub queued_block: Option<EntryStreamBlock>,
}

impl<T> EntryStreamHandler for EntryStream<T>
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)?;
Expand Down Expand Up @@ -111,24 +111,24 @@ where
}
}

pub type SocketEntryStream = EntryStream<SocketOutput>;
pub type SocketEntryStream = EntryStream<EntrySocket>;

impl SocketEntryStream {
pub fn new(socket: String, leader_scheduler: Arc<RwLock<LeaderScheduler>>) -> Self {
EntryStream {
output: SocketOutput { socket },
output: EntrySocket { socket },
leader_scheduler,
queued_block: None,
}
}
}

pub type MockEntryStream = EntryStream<VecOutput>;
pub type MockEntryStream = EntryStream<EntryVec>;

impl MockEntryStream {
pub fn new(_: String, leader_scheduler: Arc<RwLock<LeaderScheduler>>) -> Self {
EntryStream {
output: VecOutput::new(),
output: EntryVec::new(),
leader_scheduler,
queued_block: None,
}
Expand Down

0 comments on commit ba17616

Please sign in to comment.