'What does "expected struct `ParseError`, found fn item" mean?
I am working on a parser and I keep getting an error on this part of my code.
impl FromStr for Binop {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"+" => Binop::Add,
"*" => Binop::Mul,
"-" => Binop::Sub,
"/" => Binop::Div,
"<" => Binop::Lt,
"==" => Binop::Eq,
_ => {return Err(ParseError); } // <---- Error Here
})
}
}
I've tried writing an actual string inside the parenthesis and a bunch of other stuff & I just can't seem to understand what the error means.
Full error:
error[E0308]: mismatched types
--> grumpy/src/isa.rs:212:32
|
212 | _ => {return Err(ParseError); }
| ^^^^^^^^^^ expected struct `ParseError`, found fn item
|
::: grumpy/src/lib.rs:17:1
|
17 | pub struct ParseError(String);
| ------------------------------ fn(String) -> ParseError {ParseError} defined here
|
= note: expected struct `ParseError`
found fn item `fn(String) -> ParseError {ParseError}`
help: use parentheses to instantiate this tuple struct
|
212 | _ => {return Err(ParseError(_)); }
| +++
And I defined the ParseError as pub struct ParseError(String);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
