Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support anyhow crate #49

Merged
merged 4 commits into from
Aug 5, 2023
Merged

Support anyhow crate #49

merged 4 commits into from
Aug 5, 2023

Conversation

hiratara
Copy link

@hiratara hiratara commented Aug 5, 2023

Hi,

I want to use lambda_calculus and https://github.com/dtolnay/anyhow crates in my app and wrote the following codes:

fn main() -> anyhow::Result<()> {
    let mut expr = parse(&"(λm.λn.λs.λz. m s (n s z)) (λs.λz. z) (λs.λz. s z)", Classic)?;
    ...
}

But it causes the error:

error[E0277]: the trait bound `ParseError: std::error::Error` is not satisfied
 --> src/main.rs:4:89
  |
4 |     let mut expr = parse(&"(λm.λn.λs.λz. m s (n s z)) (λs.λz. z) (λs.λz. s z)", Classic)?;
  |                                                                                         ^ the trait `std::error::Error` is not implemented for `ParseError`
  |
  = help: the following other types implement trait `FromResidual<R>`:
            <Result<T, F> as FromResidual<Result<Infallible, E>>>
            <Result<T, F> as FromResidual<Yeet<E>>>
  = note: required for `anyhow::Error` to implement `From<ParseError>`
  = note: required for `Result<(), anyhow::Error>` to implement `FromResidual<Result<Infallible, ParseError>>`

This PR implements the Error trait for ParseError and allows it to be converted into anyhow::Error .

I don't feel the need to convert to anyhow::Error for the TermError, but I implemented it just in case.

Note that I'd better use the https://github.com/dtolnay/thiserror trait for this purpose, but this crate should not depend on other crates, so I didn't use it.

src/parser.rs Outdated Show resolved Hide resolved
src/parser.rs Outdated Show resolved Hide resolved
@ljedrz
Copy link
Owner

ljedrz commented Aug 5, 2023

Thanks! I agree, this is a very useful addition; just adjusting one error message and it's good to go - I will cut a release afterwards.

@ljedrz ljedrz merged commit 5791e67 into ljedrz:master Aug 5, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants