using

using is a very power construct in Odin. It imports a namespace's contents in the current scope.

using can be used in many contexts.

Import Names

import "fmt.odin";

main :: proc() {
    fmt.println("Hellope");
    // Import the contents of the import name `fmt`
    // into this scope from now on
    using fmt;
    println("Hellope");
}

Types

// Using on enums
Fruit :: enum {
    APPLE,
    BANANA,
    CITRON,
}
a: Fruit;
a = Fruit.APPLE;
using Fruit;
a = BANANA;

Variables

Vector3 :: struct {x, y, z: f32};

using v: Vector3;
// or `using v;` afterwards is fine
x = 123; // v.x = 123;
fmt.println(v);
v: Vector3;
using p := ^v;
x = 123; // p.x = 123;

results matching ""

    No results matching ""