Expand description

Object definitions for a ComponentInterface.

This module converts “interface” definitions from UDL into Object structures that can be added to a ComponentInterface, which are the main way we define stateful objects with behaviour for a UniFFI Rust Component. An Object is an opaque handle to some state on which methods can be invoked.

(The terminology mismatch between “interface” and “object” is a historical artifact of this tool prior to committing to WebIDL syntax).

A declaration in the UDL like this:

interface Example {
  constructor(string? name);
  string my_name();
};

Will result in an Object member with one Constructor and one Method being added to the resulting crate::ComponentInterface:

let obj = ci.get_object_definition("Example").unwrap();
assert_eq!(obj.name(), "Example");
assert_eq!(obj.constructors().len(), 1);
assert_eq!(obj.constructors()[0].arguments()[0].name(), "name");
assert_eq!(obj.methods().len(),1 );
assert_eq!(obj.methods()[0].name(), "my_name");

It’s not necessary for all interfaces to have constructors.

let obj = ci.get_object_definition("Example").unwrap();
assert_eq!(obj.name(), "Example");
assert_eq!(obj.constructors().len(), 0);

Structs

  • An “object” is an opaque type that is passed around by reference, can have methods called on it, and so on - basically your classic Object Oriented Programming type of deal, except without elaborate inheritance hierarchies. Some can be instantiated.

Enums

  • The list of traits we support generating helper methods for.