Skip to content

Improve generated types for constants in ros messages. #47

Description

@m-dahl

As discussed in #45, constants are currently generated like this:

#[allow(non_upper_case_globals)]
impl MyCustomMsg {
    pub const MY_CONSTANT_ONE: _bindgen_ty_139 = my_custom_package__msg__MyCustomMsg__MY_CONSTANT_ONE;
}

Instead of the actual type defined in the msg/idl file, we get a bindgen generated type. This is because constants are defined like this in the generated c header files:

enum
{
  my_custom_package__msg__MyCustomMsg__MY_CONSTANT_ONE = 1
};

If we knew the constant was a i8, we could generate the code like this instead:

#[allow(non_upper_case_globals)]
impl MyCustomMsg {
    pub const MY_CONSTANT_ONE: i8 = my_custom_package__msg__MyCustomMsg__MY_CONSTANT_ONE as i8;
}

But since we currently do not read the msg files, I am not sure how to get the actual type of the constant. It could be that we need to start reading the msg files, but that would lead to a large rewrite of the msg generation code. Maybe a fun project for the future...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions