Skip to content

Declare structs for types with more than a single ReadArgs argument #108

Open
@cmyr

Description

Currently if a type has multiple read arguments, we pass them in as a tuple, but this makes it very easy to lose track of them, especially if the arguments are of the same type. It would be nice if instead of this, we declared a struct with named fields, and used that.

In this world,

#[read_args(number_of_h_metrics: u16, num_glyphs: u16)]
table Hmtx {
    // ...
}

would produce:

pub struct HmtxArgs {
    pub number_of_h_metrics: u16,
    pub num_glyphs: u16,
}

impl ReadArgs for Hmtx {
    type Args = HmtxArgs;
}

impl<'a> FontReadWithArgs<'a> for Hmtx<'a> {
    fn read_with_args(data: FontData<'a>, args: &HmtxArgs) -> Result<Self, ReadError> {
        let HmtxArgs { number_of_h_metrics, num_glyphs } = *args;
        // ..
    }
}

instead of,

impl ReadArgs for Hmtx {
    type Args = (u16, u16);
}

impl<'a> FontReadWithArgs<'a> for Hmtx<'a> {
    fn read_with_args(data: FontData<'a>, args: &(u16, u16)) -> Result<Self, ReadError> {
        let (number_of_h_metrics, num_glyphs) = *args;
    }
}

which should be much easier to understand.

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions