StructOp Handbook
Contents Examples Commands

Crate mini

Console program226 lines of .st255 lines of generated Rust
Program output
pear=3
apple=1
fig=2
seen pear
seen apple
name pear
name apple
name fig
3 rows, 1 kept, fig 2 (true)
kiwi found: false, painted Green, max 100
packed cba; error: empty path
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"
        }
        Mini = {
            source  = "Crate/minicrate"
            version = "@latest"
        }
    }
}

Input, plan and generated Rust#

tests/bind/minicrate/minicrate.bind.st · hints for structop bind
tests/bind/minicrate/minicrate.bind.st · hints for structop bind
bind "minicrate" {
    crate   = "minicrate"
    version = "0.1.0"
    path    = "."
}

struct "Encoder" {
    W = Bytes
}

function "Db::prepare" {
    then = ["Stmt::query_map"]
    variant "db_prepare_query_map" {
        T = Int
    }
}

function "Db::get" {
    variant "db_get_int" {
        T = Int
    }
}

function "Encoder::write_all" {}
structop plan
structop plan
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.value.db
      + ability.value.rows
      + ability.value.score
      + ability.value.found
      + ability.value.name
      + ability.value.n
      + ability.value.kept
      + ability.value.err
      + ability.value.color
      + ability.value.input
      + ability.value.packed
      + ability.db_open.Open
      + ability.db_insert.Pear
      + ability.db_insert.Apple
      + ability.db_insert.Fig
      + ability.db_prepare_query_map.List
      + ability.row_name.Name
      + ability.row_n.N
      + ability.print.Row
      + ability.db_each.Count
      + ability.print.Seen
      + ability.db_names.Names
      + ability.print.Name
      + ability.db_find.Fig
      + ability.print.Fig
      + ability.db_find.Kiwi
      + ability.db_paint.Paint
      + ability.print.Kiwi
      + ability.set.Fill
      + ability.db_pack.Pack
      + ability.db_open.Bad
      + ability.print.End

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 tests/bind/minicrate/minicrate.bind.st    # from the repository root
cd crate-mini    # a folder holding the .st files above
structop init
structop plan
structop apply