StructOp Handbook
Contents Examples Commands

Crate curl

Console program88 lines of .st150 lines of generated Rust
Program output
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"
        }
    }
}

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-run
Try 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