Skip to content

IDL / Schema

The Interface Description Language (IDL, also called the schema) is what you write by hand. A schema file has the extension .ids and lives under a project's src/ directory. It defines the data shapes and the protocols that carry them, independent of any language.

greeting.ids
const GREETING_MAX: u16 = 280

enum Language {
    English
    Spanish
    Japanese
}

/// A greeting in a given language.
struct Greeting {
    message: char[max GREETING_MAX]
    language: Language
    optional sender: char[max 64]
}

protocol Greeter {
    function greet(greeting: Greeting) -> bool;
}

Declarations

A schema is a flat list of declarations, in any order:

Keyword Purpose
struct a data shape — named, typed fields
enum a closed set of named variants
protocol a set of callable functions
error a named failure with an interpolated message and fields, raised by functions with !
const a compile-time constant: const NAME: type = value
type a second name for a type: type UserId = u64
settings package/schema-wide authoring policy (key = value) — enforced at build time
validator a named, parameterised check on a field's value, run by generated code
use pull declarations in from another schema or package

Annotations

A line @key = value above a declaration, field or function configures it: @validators, @framing, @deprecated and others. See Annotations.

Comments and docs

// is a comment. /// lines are docstrings and attach to the next declaration. //! lines at the top of a file are its module docs.

Imports

imports.ids
use std::http::Request
use mypackage::{User, Post}
use external::uuid::Uuid as UUID
use parent::common::*

self::, parent:: and package:: prefixes resolve relative to the current schema. See Imports.