unicode-org / icu4x

Solving i18n for client-side and resource-constrained environments.
https://icu4x.unicode.org
Other
1.38k stars 178 forks source link

Add TinyAsciiStr::concat #5772

Closed sffc closed 2 weeks ago

sffc commented 2 weeks ago

5729

sffc commented 2 weeks ago

I considered a few other signatures. I picked this one because:

  1. If the input were a &str, we'd need to check each character again. If you want to append a &str, you can first convert it to a TinyAsciiStr of the same size as the output.
  2. concat is more general than some of the alternatives. For example, to push a single character, you can make a TinyAsciiStr<1> and then call concat.
  3. To modify the receiver, you can save the result back, as in *x = x.concat(y). Note that &mut self is not const.
  4. I saw no good reason to enforce that Q == M + N because resize already is documented to do the truncation thing, and it saves the client from having to call resize themselves.
sffc commented 2 weeks ago

@zbraniecki You can submit this (to unblock your PR) if you agree with my logic about not adding the assertion.

zbraniecki commented 2 weeks ago

I'm fine merging it as is. No blockers.