Skip to content

Trait polymorphism in blob terms #23

@matko

Description

@matko

Multiple blob types may support the same type of operation. For example, a matrix, and a window over a matrix, will both support operations like getting the width, height, row retrieval, column retrieval, etc

The normal rust thing is to have a trait which defines contracts for these operations, which both types then implement. However, since we cannot retrieve trait types directly, any foreign predicate that serves multiple blob types still has to have a big check block to see what sort of blob it is dealing with and dispatch accordingly.

It would be good if we had some way to retrieve an object from a term which is able to do this dispatch for us. Directly retrieving a dyn T would be ideal, but this may be too tricky to get right.

Maybe there could be another macro like dispatch_arc_blob!(DispatchType, TraitType, [ConcreteType1, ConcreteType2, ConcreteType2]) which generates an enum type DispatchType with cases for all given concrete types (that all implement TraitType), and provides an implementation of TraitType that dispatches to the inner object.

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