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: string
language: Language
optional sender: string
}
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 |
settings |
package/schema-wide authoring policy (key = value) — enforced at build time |
validator |
a named, parameterised field check — recorded, not yet enforced |
use |
pull declarations in from another schema or package |
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
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.