1use std::fmt;
2
3pub trait Printer {
5 type Err: std::error::Error + 'static;
7 fn print(&mut self, v: i32) -> Result<(), Self::Err>;
9}
10
11#[derive(Copy, Clone, Debug, PartialEq, Eq)]
13pub struct StdPrinter;
14
15#[derive(Copy, Clone, Debug, PartialEq, Eq)]
16pub struct EmptyError;
17
18impl fmt::Display for EmptyError {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 write!(f, "EmptyError")
21 }
22}
23
24impl std::error::Error for EmptyError {}
25
26impl Printer for StdPrinter {
27 type Err = EmptyError;
28 fn print(&mut self, v: i32) -> Result<(), Self::Err> {
29 println!("{}", v);
30 Ok(())
31 }
32}