session: rename SessionOutput to SessionInput

pull/20/head
Astro 2020-09-30 23:35:11 +02:00
parent bfdb64ffd6
commit d4e7036fab
2 changed files with 10 additions and 10 deletions

View File

@ -54,7 +54,7 @@ mod net;
mod server; mod server;
use server::Server; use server::Server;
mod session; mod session;
use session::{Session, SessionOutput}; use session::{Session, SessionInput};
mod command_parser; mod command_parser;
use command_parser::{Command, ShowCommand, PwmPin}; use command_parser::{Command, ShowCommand, PwmPin};
mod timer; mod timer;
@ -196,8 +196,8 @@ fn main() -> ! {
session.reset(); session.reset();
} else if socket.can_send() && socket.can_recv() && socket.send_capacity() - socket.send_queue() > 1024 { } else if socket.can_send() && socket.can_recv() && socket.send_capacity() - socket.send_queue() > 1024 {
match socket.recv(|buf| session.feed(buf)) { match socket.recv(|buf| session.feed(buf)) {
Ok(SessionOutput::Nothing) => {} Ok(SessionInput::Nothing) => {}
Ok(SessionOutput::Command(command)) => match command { Ok(SessionInput::Command(command)) => match command {
Command::Quit => Command::Quit =>
socket.close(), socket.close(),
Command::Reporting(reporting) => { Command::Reporting(reporting) => {
@ -413,7 +413,7 @@ fn main() -> ! {
SCB::sys_reset(); SCB::sys_reset();
} }
} }
Ok(SessionOutput::Error(e)) => { Ok(SessionInput::Error(e)) => {
let _ = writeln!(socket, "Command error: {:?}", e); let _ = writeln!(socket, "Command error: {:?}", e);
} }
Err(_) => Err(_) =>

View File

@ -38,16 +38,16 @@ impl LineReader {
} }
} }
pub enum SessionOutput { pub enum SessionInput {
Nothing, Nothing,
Command(Command), Command(Command),
Error(ParserError), Error(ParserError),
} }
impl From<Result<Command, ParserError>> for SessionOutput { impl From<Result<Command, ParserError>> for SessionInput {
fn from(input: Result<Command, ParserError>) -> Self { fn from(input: Result<Command, ParserError>) -> Self {
input.map(SessionOutput::Command) input.map(SessionInput::Command)
.unwrap_or_else(SessionOutput::Error) .unwrap_or_else(SessionInput::Error)
} }
} }
@ -106,7 +106,7 @@ impl Session {
self.report_pending[channel] = false; self.report_pending[channel] = false;
} }
pub fn feed(&mut self, buf: &[u8]) -> (usize, SessionOutput) { pub fn feed(&mut self, buf: &[u8]) -> (usize, SessionInput) {
let mut buf_bytes = 0; let mut buf_bytes = 0;
for (i, b) in buf.iter().enumerate() { for (i, b) in buf.iter().enumerate() {
buf_bytes = i + 1; buf_bytes = i + 1;
@ -125,6 +125,6 @@ impl Session {
None => {} None => {}
} }
} }
(buf_bytes, SessionOutput::Nothing) (buf_bytes, SessionInput::Nothing)
} }
} }