StructOp Handbook
Contents Examples Commands

Crate flate2

Console program140 lines of .st165 lines of generated Rust
Program output
47 bytes packed into 17, unpacked 47: hello hello hello hello hello hello hello hello
CRC-32 3106698858
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"
        }
        Zip = {
            source  = "Crate/flate2"
            version = "@latest"
        }
    }
}

Input, plan and generated Rust#

bind/flate2.bind.st · hints for structop bind
bind/flate2.bind.st · hints for structop bind
# flate2: zlib compression for Rust. The encoder and decoder are generic over where they write;
# struct hints pin that to Bytes (a Vec<u8>), and write_all comes from the std Write trait.
bind "flate2" {
    crate   = "flate2"
    version = "1.0.30"
    items   = ["Crc::new", "Crc::update", "Crc::sum", "Compression::new", "write::ZlibEncoder::new", "write::ZlibEncoder::write_all", "write::ZlibEncoder::finish", "write::ZlibDecoder::new", "write::ZlibDecoder::write_all", "write::ZlibDecoder::finish"]
}

struct "write::ZlibEncoder" {
    W = Bytes
}

struct "write::ZlibDecoder" {
    W = Bytes
}
structop plan
structop plan
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.value.input
      + ability.value.empty
      + ability.value.packed
      + ability.value.unpacked
      + ability.value.level
      + ability.value.encoder
      + ability.value.decoder
      + ability.value.crc
      + ability.value.sum
      + ability.set.Fill
      + ability.compression_new.Level
      + ability.write_zlib_encoder_new.Encoder
      + ability.write_zlib_encoder_write_all.Pack
      + ability.write_zlib_encoder_finish.Packed
      + ability.write_zlib_decoder_new.Decoder
      + ability.write_zlib_decoder_write_all.Unpack
      + ability.write_zlib_decoder_finish.Unpacked
      + ability.crc_new.Crc
      + ability.crc_update.Check
      + ability.crc_sum.Sum
      + ability.print.Show
      + ability.print.Crc

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