Managing Data with Structs and Enums

Accounts & Data

Chapter 3: Managing Data with Structs and Enums

Use Rust structs and enums to manage account data.

Custom Data Structures

  • Structs: Define account data (e.g., UserProfile).

  • Enums: Define state variants.

Example

#[account]
pub struct UserProfile {
    pub name: String,
    pub balance: u64,
}

Page Layout:

  • Header: Fixed top bar with "Solana Learn" logo, navigation, and profile icon.

  • Main Content:

    • Left Panel (50%): This text content.

    • Right Panel (50%): Code editor with struct.

  • Footer: Link to Rust Structs.

Visuals:

  • Code Editor: Highlighted struct.

  • Diagram: Struct fields mapped to account data.

Interactivity:

  • Modify struct and see account size change.

Last updated