2 Checks for instances of `map_err(|_| Some::Enum)`
5 This `map_err` throws away the original error rather than allowing the enum to contain and report the cause of the error
18 impl fmt::Display for Error {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 Error::Indivisible => write!(f, "could not divide input by three"),
22 Error::Remainder(remainder) => write!(
24 "input is not divisible by three, remainder = {}",
31 impl std::error::Error for Error {}
33 fn divisible_by_3(input: &str) -> Result<(), Error> {
36 .map_err(|_| Error::Indivisible)
38 .and_then(|remainder| {
42 Err(Error::Remainder(remainder as u8))
50 use std::{fmt, num::ParseIntError};
54 Indivisible(ParseIntError),
58 impl fmt::Display for Error {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 Error::Indivisible(_) => write!(f, "could not divide input by three"),
62 Error::Remainder(remainder) => write!(
64 "input is not divisible by three, remainder = {}",
71 impl std::error::Error for Error {
72 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
74 Error::Indivisible(source) => Some(source),
80 fn divisible_by_3(input: &str) -> Result<(), Error> {
83 .map_err(Error::Indivisible)
85 .and_then(|remainder| {
89 Err(Error::Remainder(remainder as u8))