StructOp Handbook
Contents Examples Commands

Crate std

Console program141 lines of .st162 lines of generated Rust
Program output
sorted: 1 3 5 7 9
abs: 42
parse: 123
parse x: invalid digit found in string
STRUCTOP_SEED: 1
On this page

The .st files#

intent.st
structop {
    type_app {
        exec = {
            lang     = "Rust"
            standard = "2021"
        }
    }

    lib_provider {
        Rust_lang = {
            source  = "StructOp/rust"
            version = "@latest"
        }
        Std = {
            source  = "Crate/std"
            version = "@latest"
        }
    }
}

Input, plan and generated Rust#

bind/std.bind.st · hints for structop bind
bind/std.bind.st · hints for structop bind
# The Rust standard library (std, core and alloc JSON from the nightly toolchain). Methods of
# primitive types take their value as value, text or list; generic parameters are pinned.
bind "std" {
    crate   = "std"
    version = "1.0.0"
    items   = ["env::var", "i32::abs", "str::parse", "slice::sort_unstable_by"]
}

function "env::var" {
    variant "env_var_text" {
        K = String
    }
}

function "str::parse" {
    variant "str_parse_int" {
        F = Int32
    }
}

function "slice::sort_unstable_by" {
    variant "slice_sort_unstable_by_int" {
        T = Int32
    }
}
structop plan
structop plan
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.value.nums
      + ability.value.n
      + ability.value.ord
      + ability.value.seed
      + ability.value.err
      + ability.slice_sort_unstable_by_int.Sort
      + ability.if.Before
      + ability.if.After
      + ability.set.Less
      + ability.set.Greater
      + ability.set.Equal
      + ability.print.Sorted
      + ability.i32_abs.Abs
      + ability.print.ShowAbs
      + ability.str_parse_int.Parse
      + ability.print.ShowParse
      + ability.str_parse_int.Bad
      + ability.print.ShowBad
      + ability.env_var_text.Seed
      + ability.print.ShowSeed

Plan: 1 to add, 0 to change, 0 to destroy.
Generated main.rs

To inspect this generated file, select Rust in intent.st, initialize the project and export its source.

Export locally
structop init
structop apply -source -no-run
Try it
structop bind bind/std.bind.st    # from the repository root
cd crate-std    # a folder holding the .st files above
structop init
structop plan
structop apply