Skip to content

Dance Adapters

Steve Melville edited this page Dec 14, 2024 · 2 revisions

The Uniform API provides a way to invoke an open-ended set of actions (dances) via a single dance function. The dance function takes a DanceRequest object and returns a DanceResponse object. Each dance has an adapter function (e.g., add_related_holons_adapter) and a build function that can be used to build DanceRequest objects for a given dance (e.g., build_add_related_holons_request). Dance adapter functions decode DanceRequest objects and dispatch their corresponding native function. For example, the follower function:

pub fn add_related_holons_adapter(
    context: &HolonsContext,
    request: DanceRequest,
) -> Result<ResponseBody, HolonError>
  • validates that the request is of the proper dance type, dance name, and has the proper parameters.
  • dispatches the native add_related_holons method offered by the holons crate.

Each pair of adapter/build functions should be defined in its own module (i.e., Rust file). All of the adapter files associated with a specific type (e.g., holon dances, descriptor dances) will be packaged together in a crate.

Dependencies

The dance adapter crates depend on the dances crate and the crate(s) that expose the native functions they invoke. For example, the holon_dance_adapters crate depends on the dances crate and the holons crate.

Dance Adapter Naming Conventions

Dance Adapter Crates (Grouped by Type)

Format: {type}_dance_adapters

Examples:

  • For Holon-related dances: holon_dance_adapters
  • For Descriptor-related dances: descriptor_dance_adapters

Dance Adapter Files (per Dance)

Format: {dance_name}_dance.rs

Examples:

  • For the add_related_holons dance: add_related_holons_dance.rs
  • For the remove_related_holons dance: remove_related_holons_dance.rs

Adapter Functions

The adapter function decodes the DanceRequest and dispatches the appropriate logic. Its name should clearly indicate its role as an adapter for a specific dance.

Recommended Format: {dance_name}_adapter

Examples:

  • For the add_related_holons dance: add_related_holons_adapter
  • For the remove_related_holons dance: remove_related_holons_adapter

Build Functions

The build function creates DanceRequest objects for the corresponding dance. Its name should reflect the dance and its role as a builder.

Recommended Format: build_{dance_name}_request

Examples:

  • For the add_related_holons dance: build_add_related_holons_request
  • For the remove_related_holons dance: build_remove_related_holons_request
Clone this wiki locally