Use Vec<u8> for LOCAL_STD{OUT,ERR} instead of dyn Write.

It was only ever used with Vec<u8> anyway. This simplifies some things.

- It no longer needs to be flushed, because that's a no-op anyway for
  a Vec<u8>.

- Writing to a Vec<u8> never fails.

- No #[cfg(test)] code is needed anymore to use `realstd` instead of
  `std`, because Vec comes from alloc, not std (like Write).
This commit is contained in:
Mara Bos 2020-11-03 21:44:21 +01:00
parent ccbce1d3b2
commit f534b75f05
5 changed files with 28 additions and 78 deletions

View file

@ -5,7 +5,7 @@
use std::fmt;
use std::fmt::{Display, Formatter};
use std::io::{self, set_panic, Write};
use std::io::set_panic;
use std::sync::{Arc, Mutex};
pub struct A;
@ -16,19 +16,8 @@ impl Display for A {
}
}
struct Sink;
impl Write for Sink {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Ok(buf.len())
}
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
fn main() {
set_panic(Some(Arc::new(Mutex::new(Sink))));
set_panic(Some(Arc::new(Mutex::new(Vec::new()))));
assert!(std::panic::catch_unwind(|| {
eprintln!("{}", A);
})