Skip to content

Commit

Permalink
Breaking: Hide nom error type from public API
Browse files Browse the repository at this point in the history
In #77, we made a breaking change—but I messed up the commit messages so
`semantic-version` didn't catch that, my apologies!—to upgrade the
version of `nom` we're using. That change needed to be breaking because
we expose a `nom::Err` type in `Program::from_str` in the public API.

This PR makes a small change to remove that type from the public API so
that future updates involving `nom` are no longer breaking changes.
Instead, the error type of `Program::from_str` is now `String`, which
matches `Expression::from_str`.
  • Loading branch information
Graham Enos committed Jun 15, 2022
1 parent fb20f4b commit 72fcc89
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ impl Program {
}

impl FromStr for Program {
type Err = nom::Err<String>;
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let lexed = lex(s).map_err(nom::Err::Error)?;
let lexed = lex(s)?;
let (_, instructions) = parse_instructions(&lexed).map_err(|err| match err {
nom::Err::Incomplete(_) => nom::Err::Error("incomplete".to_owned()),
nom::Err::Error(error) => nom::Err::Error(format!("{:?}", error)),
nom::Err::Failure(failure) => nom::Err::Error(format!("{:?}", failure)),
nom::Err::Incomplete(_) => "incomplete".to_owned(),
nom::Err::Error(error) => format!("{:?}", error),
nom::Err::Failure(failure) => format!("{:?}", failure),
})?;
let mut program = Self::new();

Expand Down

0 comments on commit 72fcc89

Please sign in to comment.