Your code is a bit inefficient. I took the liberty of fixing that for you: <a href="https://gist.github.com/lhecker/8e89d998c156f0bfdd2d" rel="nofollow">https://gist.github.com/lhecker/8e89d998c156f0bfdd2d</a><p>(You can use that code freely and without any attribution if you want to.)<p>The important part here is to use `String::with_capacity()` to prevent unnecessary reallocations. Furthermore I used `usize::saturating_sub()` because it's neat and cleaned up the code with `rustfmt` (which you should use).
Is there a special reason the tests are all asserting inequality? To me this only indicates if it doesn't do stuff it's not supposed to do, instead of working as intended: <a href="https://github.com/hfiguiere/leftpad-rs/blob/master/src/lib.rs#L29:L39" rel="nofollow">https://github.com/hfiguiere/leftpad-rs/blob/master/src/lib....</a><p>[edit] thanks for the explanation, I'm not familiar with rust and just assumed the bang would mean !=
I see i'm not the only one who did this. Leftpad for Swift <a href="https://github.com/coryalder/SwiftLeftpad" rel="nofollow">https://github.com/coryalder/SwiftLeftpad</a>
Lol this is all pretty funny. I also did this but in C++ to make fun of that JS crap.<p><a href="https://gist.github.com/zelcon5/7dc42bf91ea958132a0d" rel="nofollow">https://gist.github.com/zelcon5/7dc42bf91ea958132a0d</a><p>- "padding" can go either left or right.<p>- generic function<p>- minimal lines of code<p>Wow so great, make me a dependency for Windows11, Apache, Firefox, and toasters.
I'd hate to see how the borrow checker destroys objects lent to remote systems... Along the vein of <a href="https://xkcd.com/416/" rel="nofollow">https://xkcd.com/416/</a>