2

core: Implement ASCII trim functions on byte slices by dbrgn · Pull Request #936...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/93686
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Contributor

dbrgn commented 20 days ago

edited

Hi @rust-lang/libs! This is a feature that I wished for when implementing serial protocols with microcontrollers. Often these protocols may contain leading or trailing whitespace, which needs to be removed. Because oftentimes drivers will operate on the byte level, decoding to unicode and checking for unicode whitespace is unnecessary overhead.

This PR adds three new methods to byte slices:

  • trim_ascii_start
  • trim_ascii_end
  • trim_ascii

I did not find any pre-existing discussions about this, which surprises me a bit. Maybe I'm missing something, and this functionality is already possible through other means? There's rust-lang/rfcs#2547 ("Trim methods on slices"), but that has a different purpose.

As per the std dev guide, this is a proposed implementation without any issue / RFC. If this is the wrong process, please let me know. However, I thought discussing code is easier than discussing a mere idea, and hacking on the stdlib was fun.

Tracking issue: #94035


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK