Skip to content

Possible to dynamic dispatch on Device trait? #957

@Dr-TSNG

Description

@Dr-TSNG

I am trying to put different Device implementations into something like Box<dyn Device>. Moreover, I want to have something looks like

struct NetInterface {
    device: Box<dyn Device>,
    iface: Interface,
    sockets: SocketSet<'static>,
}

Without which, I have to write a lot of duplicate codes to support multiple physical network interfaces. However the trait doesn't meet object safe requirements. I wonder if this can be done with some tricks.

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