Skip to content

ParseTo trait using using generics wrong #1805

Open
@marcdejonge

Description

@marcdejonge

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions