session: eliminate copying LineResult wrapper

softspi
Astro 2020-03-18 21:33:10 +01:00
parent ac728a2aff
commit 0575b52bc1
1 changed files with 2 additions and 17 deletions

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 {
// 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),