session: eliminate copying LineResult wrapper

This commit is contained in:
Astro 2020-03-18 21:33:10 +01:00
parent ac728a2aff
commit 0575b52bc1

View File

@ -16,16 +16,13 @@ impl LineReader {
} }
} }
pub fn feed(&mut self, c: u8) -> Option<LineResult> { pub fn feed(&mut self, c: u8) -> Option<&[u8]> {
if c == 13 || c == 10 { if c == 13 || c == 10 {
// Enter // Enter
if self.pos > 0 { if self.pos > 0 {
let len = self.pos; let len = self.pos;
self.pos = 0; self.pos = 0;
Some(LineResult { Some(&self.buf[..len])
buf: self.buf.clone(),
len,
})
} else { } else {
None 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 { pub enum SessionOutput {
Nothing, Nothing,
Command(Command), Command(Command),