Skip to content

Support optional fields in request_lt! macros unsized section #38

@kstep

Description

@kstep

Unsized section of request_lt! macro can not contain Option<T> fields, as it prepends all types with reference token &'a. This is intentional, as only macro system doesn't allow to operate on lifetimes as a separate token, so I can't pass lifetime into macro directly.

Due to hygiene restrictions I either must pass field type lifetimes and struct lifetime from outside, or generate all of them inside the macro. Being unable to pass lifetimes into macro, I opted to the second option.

The problem is if the unsized field type is for example Option<str>, the generated field type will be &'a Option<str>, which would not work. The real type should be Option<&'a str>.

One of the possible solutions would be to make all unsized fields optional, so macro will just wrap all references in Option<&'a ...>. This can be somewhat unexpected to an unaware contributor, but it doesn't add any overhead, as Option<&T> is the same as &T, and None variant is just encoded as NULL pointer.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions