Crate flate2
Console program140 lines of .st165 lines of generated Rust
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"
}
}
}main.st
# zlib through the provider structop bind writes from the flate2 crate: compress a text,
# check its CRC-32, and get the text back.
ability "value" "input" {
type = Bytes
size = 64
}
data "value" "input" {
of = ability.value.input
}
ability "value" "empty" {
type = Bytes
size = 128
}
ability "value" "packed" {
type = Bytes
size = 128
}
data "value" "packed" {
of = ability.value.packed
}
ability "value" "unpacked" {
type = Bytes
size = 64
}
data "value" "unpacked" {
of = ability.value.unpacked
}
ability "value" "level" {
type = Compression
}
ability "value" "encoder" {
type = WriteZlibEncoder
}
ability "value" "decoder" {
type = WriteZlibDecoder
}
ability "value" "crc" {
type = Crc
}
ability "value" "sum" {
type = UInt32
}
data "value" "sum" {
of = ability.value.sum
}
ability "set" "Fill" {
target = ability.value.input
value = bytes("hello hello hello hello hello hello hello hello")
}
ability "compression_new" "Level" {
level = 6
target = ability.value.level
}
ability "write_zlib_encoder_new" "Encoder" {
w = ability.value.empty
level = ability.value.level
target = ability.value.encoder
}
ability "write_zlib_encoder_write_all" "Pack" {
zlib_encoder = ability.value.encoder
buf = ability.value.input
}
ability "write_zlib_encoder_finish" "Packed" {
zlib_encoder = ability.value.encoder
target = ability.value.packed
}
ability "write_zlib_decoder_new" "Decoder" {
w = ability.value.empty
target = ability.value.decoder
}
ability "write_zlib_decoder_write_all" "Unpack" {
zlib_decoder = ability.value.decoder
buf = ability.value.packed
}
ability "write_zlib_decoder_finish" "Unpacked" {
zlib_decoder = ability.value.decoder
target = ability.value.unpacked
}
ability "crc_new" "Crc" {
target = ability.value.crc
}
ability "crc_update" "Check" {
crc = ability.value.crc
data = ability.value.input
}
ability "crc_sum" "Sum" {
crc = ability.value.crc
target = ability.value.sum
}
ability "print" "Show" {
message = "${length(data.value.input.current)} bytes packed into ${length(data.value.packed.current)}, unpacked ${length(data.value.unpacked.current)}: ${text(data.value.unpacked.current)}"
}
ability "print" "Crc" {
message = "CRC-32 ${data.value.sum.current}"
}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-runTry 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