From 0575b52bc10a6f24000402244d9abd66725bc5e4 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 18 Mar 2020 21:33:10 +0100 Subject: [PATCH] session: eliminate copying LineResult wrapper --- src/session.rs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/session.rs b/src/session.rs index 82be344..6136c55 100644 --- a/src/session.rs +++ b/src/session.rs @@ -16,16 +16,13 @@ impl LineReader { } } - pub fn feed(&mut self, c: u8) -> Option { + pub fn feed(&mut self, c: u8) -> Option<&[u8]> { if c == 13 || c == 10 { // Enter if self.pos > 0 { let len = self.pos; self.pos = 0; - Some(LineResult { - buf: self.buf.clone(), - len, - }) + Some(&self.buf[..len]) } else { None } @@ -41,18 +38,6 @@ impl LineReader { } } -pub struct LineResult { - buf: [u8; MAX_LINE_LEN], - len: usize, -} - -impl Deref for LineResult { - type Target = [u8]; - fn deref(&self) -> &Self::Target { - &self.buf[..self.len] - } -} - pub enum SessionOutput { Nothing, Command(Command),