LogoMist

Structs

Data modeling with Mist's name-first field convention.

Structs in Mist follow the same structural logic as Rust, with fields using the language-wide name Type convention and comma-separated grouping.

Basic Syntax

A struct is defined by its name followed by a block of fields. Each field places the identifier before the type.

pub struct Task {
    pub name String,
    pub state TaskState,
    pub executions i32,
}

Visibility

Use the pub modifier to make the struct or its individual fields accessible from other modules.

pub struct NetworkNode {
    pub id u32,
    address *str,
}

Instantiation

Structs are instantiated using the standard brace syntax.

let task = Task {
    name: "Initialize".to_string(),
    state: TaskState::Pending,
    executions: 0,
};

Destructuring

Struct patterns use let with the struct name and field bindings:

let p = Point { x: 3, y: 4 };
let Point { x, y } = p;

Generics & Lifetimes

Generics and lifetimes are declared in angle brackets after the struct name. Reference types use the * prefix.

pub struct Buffer<'a, T> {
    pub data *'a T,
    pub len usize,
}

Key Characteristics

  • Name-First Declaration: Fields use name Type order, consistent with function parameters and variable declarations.
  • Comma-Separated Members: Fields are separated by commas, maintaining a clean delimiter style.
  • Rust Compatibility: Maps 1:1 to Rust structs, ensuring zero-cost abstraction and full ecosystem interoperability.
  • Direct Visibility: The pub modifier controls access at the struct and field level.

On this page