Skip to content

Improvement for static array support #48

@JiangengDong

Description

@JiangengDong

I came into a problem with static array support when using r2r.

As is described in the ROS 2 interfaces, ROS message supports static arrays where the array size is known at compile time.

For example, if I have a message ValueGroup.msg,

# file: example/msg/ValueGroup.msg
uint8[5] values

The corresponding C struct is

typedef struct example__msg__ValueGroup
{
  uint8_t values[6];
} example__msg__ValueGroup;

However, the generated Rust binding uses Vec.

pub struct ValueGroup {
    values: Vec<u8>
}

And the publisher panics if it receives a ValueGroup with an incorrect size.

I saw a comment from 4 years ago. https://github.com/sequenceplanner/r2r/blob/master/r2r_msg_gen/src/lib.rs#L392

// actually lets use a vector anyway because its more convenient with traits. assert on the fixed size instead!

However, since "const generic" has been stable for a long time (since Rust 1.51), is it possible to bring the static array back?

Again thanks for writing and maintaining this awesome crate! Forgive me if I raise issues too frequently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions