StructOp Handbook
Contents Examples Commands

Crate rusqlite

Console program94 lines of .st149 lines of generated Rust
Program output
name=apple n=1
name=fig n=2
name=pear n=3
error: no such column: nope in SELECT nope FROM fruit at offset 7
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"
        }
        Db = {
            source  = "Crate/rusqlite"
            version = "@latest"
        }
    }
}

Input, plan and generated Rust#

bind/rusqlite.bind.st · hints for structop bind
bind/rusqlite.bind.st · hints for structop bind
# rusqlite: SQLite for Rust. P = Nothing passes no query parameters; the then chain keeps the
# borrowed Statement inside one ability; Row::get is pinned once for text and once for numbers.
bind "rusqlite" {
    crate    = "rusqlite"
    version  = "0.31.0"
    features = ["bundled"]
    items    = ["Connection::open_in_memory", "Connection::execute_batch", "Connection::prepare", "Row::get"]
}

function "Connection::prepare" {
    then = ["Statement::query_map"]
    variant "connection_prepare_query_map" {
        P = Nothing
        T = Int
    }
}

function "Row::get" {
    variant "row_get_text" {
        I = Size
        T = String
    }
    variant "row_get_int" {
        I = Size
        T = Int
    }
}
structop plan
structop plan
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.value.db
      + ability.value.name
      + ability.value.n
      + ability.value.err
      + ability.connection_open_in_memory.Open
      + ability.connection_execute_batch.Fill
      + ability.connection_prepare_query_map.List
      + ability.row_get_text.Name
      + ability.row_get_int.N
      + ability.print.Row
      + ability.connection_prepare_query_map.Broken
      + ability.print.Error

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