Import Statements

If the script environment includes additional packages through which the host system exports extra APIs (such as Rust functions or constants), the script can inject these API identifiers into the current namespace scope using the use <package>; statement.

use algebra;

// Calls the function "vec" from the imported package "algebra".
let v = vec(0.0, 1.0);

By importing identifiers from a package, they shadow any previously introduced identifiers, similar to variable shadowing.

let vec = 10;

{
    use algebra;
    
    vec(0.0, 1.0); // Refers to the "algebra.vec" function.
}

// Outside of the block, the original `vec` variable is no longer shadowed.
vec == 10;

Note that you can refer to package identifiers directly without importing them. Additionally, you can always refer to the current package using the built-in crate identifier, which cannot be shadowed.

let vec = 10;

algebra.vec(0.0, 1.0);

let algebra = 20;

crate.algebra.vec(0.0, 1.0);

// Since the "algebra" package is shadowed by the `algebra` variable, you can
// import this package using the `crate` built-in identifier.
use crate.algebra;

// Refers to the "algebra.vec" function.
vec(0.0, 1.0);