TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Leftpad-rs

24 pointsby omn1about 9 years ago

8 comments

lheckerabout 9 years ago
Your code is a bit inefficient. I took the liberty of fixing that for you: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;lhecker&#x2F;8e89d998c156f0bfdd2d" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;lhecker&#x2F;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&#x27;s neat and cleaned up the code with `rustfmt` (which you should use).
评论 #11372096 未加载
评论 #11372085 未加载
jrnkntlabout 9 years ago
Is there a special reason the tests are all asserting inequality? To me this only indicates if it doesn&#x27;t do stuff it&#x27;s not supposed to do, instead of working as intended: <a href="https:&#x2F;&#x2F;github.com&#x2F;hfiguiere&#x2F;leftpad-rs&#x2F;blob&#x2F;master&#x2F;src&#x2F;lib.rs#L29:L39" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hfiguiere&#x2F;leftpad-rs&#x2F;blob&#x2F;master&#x2F;src&#x2F;lib....</a><p>[edit] thanks for the explanation, I&#x27;m not familiar with rust and just assumed the bang would mean !=
评论 #11351737 未加载
评论 #11351741 未加载
评论 #11351735 未加载
评论 #11351731 未加载
kennywinkerabout 9 years ago
I see i&#x27;m not the only one who did this. Leftpad for Swift <a href="https:&#x2F;&#x2F;github.com&#x2F;coryalder&#x2F;SwiftLeftpad" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;coryalder&#x2F;SwiftLeftpad</a>
评论 #11352033 未加载
zelcon5about 9 years ago
Lol this is all pretty funny. I also did this but in C++ to make fun of that JS crap.<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;zelcon5&#x2F;7dc42bf91ea958132a0d" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;zelcon5&#x2F;7dc42bf91ea958132a0d</a><p>- &quot;padding&quot; 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.
footaabout 9 years ago
I&#x27;d hate to see how the borrow checker destroys objects lent to remote systems... Along the vein of <a href="https:&#x2F;&#x2F;xkcd.com&#x2F;416&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xkcd.com&#x2F;416&#x2F;</a>
DanSmoothabout 9 years ago
inb4 &quot;leftpad-as-a-service&quot;...
评论 #11351813 未加载
venomsnakeabout 9 years ago
Leftpad should be the new fizzbuzz in interviews.
评论 #11372088 未加载
xgbiabout 9 years ago
So, what is the point of this? Highlight that it is possible to do to Cargo what leftpad has made to NPM?
评论 #11351788 未加载
评论 #11352712 未加载
评论 #11372092 未加载