rust-analyzer / smol_str

Apache License 2.0
447 stars 54 forks source link

Add `SmolStrBuilder` / `SmolStrBuffer` #70

Closed alexheretic closed 2 months ago

alexheretic commented 9 months ago

To build a SmolStr from parts it would be useful to have a writeable builder.

Perhaps something like

let mut result = SmolStrBuffer::new();
for part in parts {
    result.push_str(part);
}
let result = SmolStr::from(result);

This almost already exists provided by smol_str::Writer, but using this has a couple of downsides

It seems straightforward to adapt Writer to this end.

Veykril commented 9 months ago

Writer was added as an implementation detail for the format_smolstr! macro, but we certainly could expose this with a nice API.