Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SmolStrBuilder / SmolStrBuffer #70

Closed
alexheretic opened this issue Feb 7, 2024 · 1 comment · Fixed by #84
Closed

Add SmolStrBuilder / SmolStrBuffer #70

alexheretic opened this issue Feb 7, 2024 · 1 comment · Fixed by #84

Comments

@alexheretic
Copy link
Contributor

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

  • Writer is hidden from docs, implying it isn't covered by stability guarantees.
  • Writer doesn't provide infallible push_str, though it trivially could.

It seems straightforward to adapt Writer to this end.

@Veykril
Copy link
Member

Veykril commented Feb 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants