Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Modules & Imports

Modules

File-Based Modules

Declare a module that maps to a file:

mod utils

This looks for utils.ore in the same directory.

Inline Modules

Define a module’s contents inline:

mod math:
  fn add(x: i64, y: i64) -> i64:
    x + y

Inline modules can contain any items (structs, functions, nested modules, etc.):

pvt mod helpers:
  struct Helper
  fn assist() -> i64:
    42

Visibility and Attributes

pvt mod internal

#[cfg(test)]
mod tests:
  fn test_add() -> bool:
    true

Imports

Simple Path

Import a module:

use std::io

Specific Item

use std::io::File

Glob Import

Import everything from a module:

use std::io::*

Aliases

Rename on import:

use std::io as sio
use std::io::File as F

Tree Imports

Import multiple items from the same path:

use std::io::{File, BufReader}

Nested trees:

use std::{io::{File, BufReader}, collections::HashMap}

Aliases inside trees:

use std::io::{File, Write as W}

Special Path Segments

SegmentMeaning
superParent module
ignotPackage/crate root
selfCurrent module
use super::something
use super::super::deep
use ignot::parser::ast::Item
use std::io::{self, File}

Private Imports

pvt use std::io::File