Skip to content

Documentation doesn't mention non-enum repr directive #340

Description

@Darxoon

The attribute documentation already mentions that the repr directive can be used on enums to specify what they should be represented as (https://docs.rs/binrw/latest/binrw/docs/attribute/index.html#repr).

What it does not mention, however, is that the directive can also be used on fields and on types that are not enums, where it will behave similarly: internally, binrw will read/write the type passed to the repr directive instead of the field's type and cast them into each other using From/Into (useful if you need to serialize a third party type that doesn't support binrw and imo nicer to use than parse_ and write_with).

I'm not sure if this use case is just a side effect of its enum use case or an intentional feature but regardless, since it's absolutely possible to use it this way, I think this should be mentioned in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions