Skip to main content

Crate afia_component_sys

Crate afia_component_sys 

Source
Expand description

§afia-component-sys

A low-level Rust wrapper for libafia_component.

§Overview

libafia_component is a static library that provides a C interface for implementing and testing Afia site components. It can be downloaded from https://afiaproject.com .

The afia-component-sys crate wraps libafia_component in a low-level Rust interface.

For example, this crate exposes libafia_component’s create_element function like so:

// Links to `libafia_component` and re-exports its `create_element` function
// as a Rust function.
#[link(name = "afia_component")]
extern "C" {
    pub fn create_element(
        host_handle: *const std::ffi::c_void,
        tag_name_ptr: *const u8,
        tag_name_len: usize,
    ) -> i64;
}

§Adding Bindings

As a starting point, we are adding bindings by hand. Bindings are written in src/lib.rs. In the future, Afia distributions will include header files and JSON files that describe the libafia_component interface. After that we can explore automatically generating afia-component-sys’s bindings. In the future, after Afia we can explore automatically generating these bindings.

§To Test

cargo test -p afia-component-sys

§Optional Features

  • emulate-imports - Instead of importing functionality from the Afia host, expose an EmulatedImports that can be used to emulate the Afia host. Useful when testing a component.
  • test-utils - Exposes types that are useful for testing.

Structs§

AllocatedString
A pointer and length pair for a UTF-8 string.

Functions§

create_element
create_stripe_elements
create_text
dialog_element_close
dialog_element_show_modal
dom_element_add_event_listener
dom_element_append_child
dom_element_next_element_sibling
dom_element_previous_element_sibling
dom_element_remove_attribute
dom_element_set_attribute
dom_element_set_text_content
dom_event_prevent_default
dom_event_target
dom_node_get_property_bool
dom_node_get_property_string
dom_node_set_property_bool
dom_node_set_property_string
element_child_nodes
element_click
element_get_attribute
element_inner_text
element_tag_name
initialize_stripe
input_element_value
local_storage_get_item
local_storage_set_item
node_list_item
node_type
output_may_have_changed
parent_node
submit_stripe_elements