function_string_builder

Crates.iofunction_string_builder
lib.rsfunction_string_builder
version1.0.3
sourcesrc
created_at2023-05-13 20:48:51.210733
updated_at2023-05-14 07:48:07.678131
descriptionA string builder that takes a user-provided function
homepage
repository
max_upload_size
id863925
size3,159
(megahomyak)

documentation

README

A new approach to building strings

Instead of maintaining a buffer, this thing minimizes the amount of allocations by calling the user-provided function two times: the first time it sums the lengths of the strings returned using a callback by the function, the second time it pushes said strings into a String that was extended using the lengths sum.

Such approach is aimed at minimizing the amount and size of allocations as much as possible.

An example

assert_eq!(
    build(|mut collector| {
        collector.collect("a");
        collector.collect("bcd");
        collector.collect("ef");
    }),
    "abcdef"
);
Commit count: 0

cargo fmt