Crate curl
Console program88 lines of .st150 lines of generated Rust
fetched: Hello from a local file, fetched by libcurl.
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"
}
Curl = {
source = "Crate/curl"
version = "@latest"
}
}
}main.st
# libcurl through the provider structop bind writes from the curl crate: read a local file through
# a file:// address (no network), collecting the text in the transfer's write closure.
ability "value" "easy" {
type = Easy
}
ability "value" "dir" {
type = String
}
data "value" "dir" {
of = ability.value.dir
}
ability "value" "body" {
type = String
size = 256
}
data "value" "body" {
of = ability.value.body
}
ability "value" "reason" {
type = String
}
data "value" "reason" {
of = ability.value.reason
}
ability "env_var_text" "Dir" {
key = "PWD"
target = ability.value.dir
}
ability "easy_new" "Init" {
target = ability.value.easy
}
ability "easy_url" "Address" {
easy = ability.value.easy
url = "file://${data.value.dir.current}/hello.txt"
}
ability "easy_transfer_write_function_perform" "Fetch" {
easy = ability.value.easy
f = [ability.append.Chunk]
f_result = size(length(data.easy_transfer_write_function_perform_f.C.arg1))
error = ability.value.reason
}
data "easy_transfer_write_function_perform_f" "C" {
of = ability.easy_transfer_write_function_perform.Fetch
}
ability "append" "Chunk" {
target = ability.value.body
value = "${text(data.easy_transfer_write_function_perform_f.C.arg1)}"
}
ability "print" "Body" {
message = "fetched:\n${data.value.body.current}${data.value.reason.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
}
}bind/curl-crate.bind.st · hints for structop bind
bind/curl-crate.bind.st · hints for structop bind
# The curl crate: Easy::write_function wants a 'static closure, which cannot reach the program,
# so it is reported as skipped; the scoped form transfer, write_function, perform is one chain.
bind "curl" {
crate = "curl"
version = "0.4.46"
items = ["easy::Easy::new", "easy::Easy::url", "easy::Easy::write_function", "easy::Easy::transfer"]
}
function "easy::Easy::transfer" {
then = ["easy::Transfer::write_function", "easy::Transfer::perform"]
}structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.easy
+ ability.value.dir
+ ability.value.body
+ ability.value.reason
+ ability.env_var_text.Dir
+ ability.easy_new.Init
+ ability.easy_url.Address
+ ability.easy_transfer_write_function_perform.Fetch
+ ability.append.Chunk
+ ability.print.Body
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
structop bind bind/curl-crate.bind.st # from the repository root
cd crate-curl # a folder holding the .st files above
structop init
structop plan
structop apply