Crates.io | capacity_builder |
lib.rs | capacity_builder |
version | |
source | src |
created_at | 2024-12-09 05:56:02.420993 |
updated_at | 2024-12-10 03:19:54.67829 |
description | Builders where the code to calculate the capacity is the same as the code to write what's being built. |
homepage | |
repository | https://github.com/dsherret/capacity_builder |
max_upload_size | |
id | 1476975 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
capacity_builder
Builders where the code to calculate the capacity is the same as the code to write what's being built.
Sometimes you have some complex code that would be a bit of a pain to calculate the capacity of or could risk easily getting out of sync with the implementation. This crate makes keeping it in sync easier because it's the same code.
use capacity_builder::StringBuilder;
let text = StringBuilder::build(|builder| {
for (i, import_module) in import_modules.iter().enumerate() {
builder.append("// ");
builder.append(i);
builder.append(" import\n");
builder.append("import \"");
builder.append(import_module);
builder.append("\";\n");
}
})?;
Behind the scenes it runs the closure once to compute the capacity and a second time to write the string.