<aside> 🚧

Note that some of this API is not yet implemented. This document act as a “pretend documentation” of the macro API to collect early feedback before implementing it.

</aside>

Design principles

  1. The API should extract as much information from the Rust code as possible, even with limited use of macros.
  2. The API should be enough to generate any Codama IDL.
  3. The API should not get in the way of the developer or influence implementation decisions.
  4. The API should be as intuitive as possible.
  5. The API should not conflict with the namespaces of other libraries — i.e. all macros start with #[codama(...)].
  6. The DefaultPlugin should only export IDL items that are explicitly whitelisted using Codama derives — e.g. CodamaAccount.

High-level API

The Codama struct provides an entry-point to the Codama Macro API. Simply use the load method to fetch all files from the provided crate directory and create a Codama instance. You can then use methods such as get_idl to get the RootNode of the Codama IDL or get_json_idl if you want it in JSON format.

let codama = Codama::load(&Path::new("path/to/my/crate"))?;
let idl: RootNode = codama.get_idl()?;
let json_idl: String = codama.get_json_idl()?;

API

Types

Any data structure defined in Rust as the potential to be exported as DefinedTypeNodes as long as they use the CodamaType derive and all types in fields/variants have been properly identified.

#[derive(CodamaType)]
struct Person {
    name: String,
    age: u16,
}