String.shrink

Requests the string to reduce its capacity to fit the size.

The request is non-binding. The string won't become smaller than the string byte length.

struct String
@nogc nothrow pure @trusted
void
shrink
(
const size_t size
)

Parameters

size size_t

Desired size.

Examples

auto s = String("Die Alten lasen laut.");
assert(s.capacity == 21);

s.reserve(30);
s.shrink(25);
assert(s.capacity == 25);

s.shrink(18);
assert(s.capacity == 21);

s.shrink(22);
assert(s.capacity == 21);

Meta