2 Checks for public functions that return a `Result`
3 with an `Err` type of `()`. It suggests using a custom type that
4 implements `std::error::Error`.
7 Unit does not implement `Error` and carries no
8 further information about what went wrong.
11 Of course, this lint assumes that `Result` is used
12 for a fallible operation (which is after all the intended use). However
13 code may opt to (mis)use it as a basic two-variant-enum. In that case,
14 the suggestion is misguided, and the code should use a custom enum
19 pub fn read_u8() -> Result<u8, ()> { Err(()) }
26 pub struct EndOfStream;
28 impl fmt::Display for EndOfStream {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 write!(f, "End of Stream")
34 impl std::error::Error for EndOfStream { }
36 pub fn read_u8() -> Result<u8, EndOfStream> { Err(EndOfStream) }
39 Note that there are crates that simplify creating the error type, e.g.
40 [`thiserror`](https://docs.rs/thiserror).