mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-18 06:58:10 -05:00
Only trigger write when needed
This commit is contained in:
parent
e811dd15b5
commit
74388d4bf4
1 changed files with 4 additions and 2 deletions
|
@ -47,8 +47,10 @@ pub trait CountedWrite<'a> {
|
||||||
impl<'a, 'b> CountedWrite<'b> for MaxLenWriter<'a, 'b> {
|
impl<'a, 'b> CountedWrite<'b> for MaxLenWriter<'a, 'b> {
|
||||||
fn write_ascii(&mut self, ascii: &[u8]) -> io::Result<()> {
|
fn write_ascii(&mut self, ascii: &[u8]) -> io::Result<()> {
|
||||||
let n = ascii.len().min(self.max_len.saturating_sub(self.len));
|
let n = ascii.len().min(self.max_len.saturating_sub(self.len));
|
||||||
|
if n > 0 {
|
||||||
self.stdout.write_all(&ascii[..n])?;
|
self.stdout.write_all(&ascii[..n])?;
|
||||||
self.len += n;
|
self.len += n;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue