Skip to content

feat: derive enum (xtype union) #504

@carlocorradini

Description

@carlocorradini

Currently, as far as I know, xtype union (enum) are not supported.
DdsType does not raise any compile-time error, but when an enum (xtype union) is used, for example, during a write operation, the program crashes with "not yet implemented” error".

The following straightforward example compiles successfully but crashes when .write(...) is called.

use dust_dds::{
    domain::domain_participant_factory::DomainParticipantFactory,
    infrastructure::{
        qos::QosKind,
        status::NO_STATUS,
        type_support::{DdsType, TypeSupport},
    },
    listener::NO_LISTENER,
};

#[derive(DdsType)]
enum TestUnion {
    U8(u8),
    U16(u16),
}

fn main() {
    let domain_participant = DomainParticipantFactory::get_instance()
        .create_participant(1, QosKind::Default, NO_LISTENER, NO_STATUS)
        .unwrap();
    let topic = domain_participant
        .create_topic::<TestUnion>(
            "test",
            TestUnion::get_type_name(),
            QosKind::Default,
            NO_LISTENER,
            NO_STATUS,
        )
        .unwrap();
    let publisher = domain_participant
        .create_publisher(QosKind::Default, NO_LISTENER, NO_STATUS)
        .unwrap();
    let writer = publisher
        .create_datawriter::<TestUnion>(&topic, QosKind::Default, NO_LISTENER, NO_STATUS)
        .unwrap();

    // PANICS: "not yet implemented"
    writer.write(TestUnion::U8(128), None).unwrap();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Medium difficultyMedium issue which can be prioritized by a sponsorsponsor wantedSeeking a sponsor to prioritize and implement this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions