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

ParseTo trait using using generics wrong #1805

Open
marcdejonge opened this issue Jan 29, 2025 · 1 comment
Open

ParseTo trait using using generics wrong #1805

marcdejonge opened this issue Jan 29, 2025 · 1 comment
Milestone

Comments

@marcdejonge
Copy link
Contributor

Hi!

I was working on a project to generate nom parse functions using macros. But I'm running into the problem that automatically supporting floating numbers is hard, because of how the ParseTo trait is implemented. For example, the float function currently expects that ParseTo<f32> should be implemented. But to support this in my generic trait, every potential importer would need to add that constraint.

I think that the type R on ParseTo should not be on the trait itself, but on the function. Then the trait becomes easier to use. An improved version would look something like:

pub trait ParseTo {
  fn parse_to<R: FromStr>(&self) -> Option<R>;
}

I'll work on a PR to open soon, so we can check the impact.

@Geal
Copy link
Collaborator

Geal commented Feb 8, 2025

that looks useful yes, but that's not someting I would merge for the moment, as that will make a breaking change in the public API. Noting this for nom 9

@Geal Geal added this to the 9.0 milestone Feb 8, 2025
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

No branches or pull requests

2 participants