Crate std
Console program141 lines of .st162 lines of generated Rust
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"
}
}
}main.st
# The Rust standard library through the provider structop bind writes: sort_unstable_by calls a
# closure returning an Ordering, abs, parse (with its error) and env::var, like lib-libc.
ability "value" "nums" {
type = List
of = Int32
size = 8
initial = [5, 3, 9, 1, 7]
}
data "value" "nums" {
of = ability.value.nums
}
ability "value" "n" {
type = Int32
}
data "value" "n" {
of = ability.value.n
}
ability "value" "ord" {
type = CmpOrdering
}
data "value" "ord" {
of = ability.value.ord
}
ability "value" "seed" {
type = String
}
data "value" "seed" {
of = ability.value.seed
}
ability "value" "err" {
type = String
}
data "value" "err" {
of = ability.value.err
}
ability "slice_sort_unstable_by_int" "Sort" {
list = ability.value.nums
compare = [ability.if.Before]
compare_result = data.value.ord.current
}
data "slice_sort_unstable_by_int_compare" "Cmp" {
of = ability.slice_sort_unstable_by_int.Sort
}
ability "if" "Before" {
condition = data.slice_sort_unstable_by_int_compare.Cmp.arg1 < data.slice_sort_unstable_by_int_compare.Cmp.arg2
then = [ability.set.Less]
else = [ability.if.After]
}
ability "if" "After" {
condition = data.slice_sort_unstable_by_int_compare.Cmp.arg1 > data.slice_sort_unstable_by_int_compare.Cmp.arg2
then = [ability.set.Greater]
else = [ability.set.Equal]
}
ability "set" "Less" {
target = ability.value.ord
value = CmpOrdering.Less
}
ability "set" "Greater" {
target = ability.value.ord
value = CmpOrdering.Greater
}
ability "set" "Equal" {
target = ability.value.ord
value = CmpOrdering.Equal
}
ability "print" "Sorted" {
message = "sorted: ${data.value.nums.current[0]} ${data.value.nums.current[1]} ${data.value.nums.current[2]} ${data.value.nums.current[3]} ${data.value.nums.current[4]}"
}
ability "i32_abs" "Abs" {
value = -42
target = ability.value.n
}
ability "print" "ShowAbs" {
message = "abs: ${data.value.n.current}"
}
ability "str_parse_int" "Parse" {
text = "123"
target = ability.value.n
}
ability "print" "ShowParse" {
message = "parse: ${data.value.n.current}"
}
ability "str_parse_int" "Bad" {
text = "x"
error = ability.value.err
}
ability "print" "ShowBad" {
message = "parse x: ${data.value.err.current}"
}
ability "env_var_text" "Seed" {
key = "STRUCTOP_SEED"
target = ability.value.seed
}
ability "print" "ShowSeed" {
message = "STRUCTOP_SEED: ${data.value.seed.current}"
}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-runTry 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