fn mask_parse_error(
    mask_kind: &str,
    string: &str,
    e: bellframe::mask::ParseError,
) -> anyhow::Error {
    use bellframe::mask::ParseError as PE;
    let mut s = format!("Can't parse {} {:?}: ", mask_kind, string);
    match e {
        PE::MultipleGlobs => {
            s.push_str("too many `*`s.  Masks can only have one region with `x` or `*`.");
        }
        PE::BellExceedsStage(bell, stage) => {
            write!(s, "bell {} is out of stage {}", bell, stage).unwrap();
        }
        PE::MismatchedLength(len, stage) => match len.cmp(&stage.num_bells()) {
            Ordering::Less => write!(
                s,
                "mask is too short; did you mean `{}*` or `{}{}`?",
                string,
                string,
                stage
                    .bells()
                    .skip(len)
                    .map(|b| b.to_char().unwrap())
                    .collect::<String>()
            )
            .unwrap(),
            Ordering::Equal => unreachable!(),
            Ordering::Greater => write!(
                s,
                "mask is too long, needing at least {} bells (too many for {})",
                len, stage
            )
            .unwrap(),
        },
    }
    anyhow::Error::msg(s)
}
/// Construct a human-friendly error message when a mask fails to parse.
Construct a human-friendly error message when a mask fails to parse.
Construct a human - friendly error message when a mask fails to parse .
fn mask_parse_error(
    mask_kind: &str,
    string: &str,
    e: bellframe::mask::ParseError,
) -> anyhow::Error {
    use bellframe::mask::ParseError as PE;
    let mut s = format!("Can't parse {} {:?}: ", mask_kind, string);
    match e {
        PE::MultipleGlobs => {
            s.push_str("too many `*`s.  Masks can only have one region with `x` or `*`.");
        }
        PE::BellExceedsStage(bell, stage) => {
            write!(s, "bell {} is out of stage {}", bell, stage).unwrap();
        }
        PE::MismatchedLength(len, stage) => match len.cmp(&stage.num_bells()) {
            Ordering::Less => write!(
                s,
                "mask is too short; did you mean `{}*` or `{}{}`?",
                string,
                string,
                stage
                    .bells()
                    .skip(len)
                    .map(|b| b.to_char().unwrap())
                    .collect::<String>()
            )
            .unwrap(),
            Ordering::Equal => unreachable!(),
            Ordering::Greater => write!(
                s,
                "mask is too long, needing at least {} bells (too many for {})",
                len, stage
            )
            .unwrap(),
        },
    }
    anyhow::Error::msg(s)
}
fn mask_parse_error ( mask_kind : & str , string : & str , e : bellframe :: mask :: ParseError , ) -> anyhow :: Error { use bellframe :: mask :: ParseError as PE ; let mut s = format ! ( " " mask_kind string ) ; match e { PE :: MultipleGlobs => { s . push_str ( " " ) ; } PE :: BellExceedsStage ( bell , stage ) => { write ! ( s " " bell stage ) . unwrap ( ) ; } PE :: MismatchedLength ( len , stage ) => match len . cmp ( & stage . num_bells ( ) ) { Ordering :: Less => write ! ( s " " string string stage bells ( ) skip ( len ) map ( b b to_char ( ) unwrap ( ) ) collect String ( ) ) . unwrap ( ) , Ordering :: Equal => unreachable ! ( ) , Ordering :: Greater => write ! ( s " " len stage ) . unwrap ( ) , } , } anyhow :: Error :: msg ( s ) }
Construct a human-friendly error message when a mask fails to parse.
Construct a human - friendly error message when a mask fails to parse .
mask_kind
&str
string
&str
e
bellframe::mask::ParseError
mask_kind
&str
string
&str
e
bellframe::mask::ParseError