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

core: Implement ASCII trim functions on byte slices #93686

Merged
merged 1 commit into from
Feb 20, 2022

Conversation

dbrgn
Copy link
Contributor

@dbrgn dbrgn commented Feb 6, 2022

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

@rust-highfive
Copy link
Collaborator

r? @yaahc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 6, 2022
library/core/src/slice/ascii.rs Outdated Show resolved Hide resolved
@leonardo-m
Copy link

Some more ASCII functions could be useful. There are probably crates to do this, but I think such functions are commonly desired, simple, there are probably very few ways to implement them, and they aren't going to change much if they are well designed. So I think they could qualify for the stdlib.

@rust-log-analyzer

This comment has been minimized.

@joshtriplett
Copy link
Member

Seems reasonable to me. r=me with the fixup commits squashed and CI passing.

@dbrgn
Copy link
Contributor Author

dbrgn commented Feb 9, 2022

Great, commits are now squashed!

Is there a way to solve this rustdoc linking issue?

std/io/struct.IoSlice.html:845: broken link - `std/io/primitive.u8.html`
std/io/struct.IoSlice.html:854: broken link - `std/io/primitive.u8.html`
std/io/struct.IoSlice.html:864: broken link - `std/io/primitive.u8.html`
std/io/struct.IoSliceMut.html:1829: broken link - `std/io/primitive.u8.html`
std/io/struct.IoSliceMut.html:1838: broken link - `std/io/primitive.u8.html`
std/io/struct.IoSliceMut.html:1848: broken link - `std/io/primitive.u8.html`
std/vec/struct.Vec.html:2801: broken link - `std/vec/primitive.u8.html`
std/vec/struct.Vec.html:2810: broken link - `std/vec/primitive.u8.html`
std/vec/struct.Vec.html:2820: broken link - `std/vec/primitive.u8.html`

This is the link: [u8::is_ascii_whitespace]: primitive.u8.html#method.is_ascii_whitespace. It works fine in the slice docs, but not when re-exported into the Vec docs.

@dbrgn dbrgn force-pushed the trim-on-byte-slices branch 2 times, most recently from d10e41c to 5f08b29 Compare February 10, 2022 12:58
@dbrgn
Copy link
Contributor Author

dbrgn commented Feb 10, 2022

For now, I removed the links from the docs. It reduces user-friendliness a bit, but at least the links aren't broken in some parts of the docs. (Here's the diff.) This should get CI passing.

@dbrgn
Copy link
Contributor Author

dbrgn commented Feb 10, 2022

r? @joshtriplett

@rust-highfive rust-highfive assigned joshtriplett and unassigned yaahc Feb 10, 2022
@workingjubilee
Copy link
Member

workingjubilee commented Feb 12, 2022

As this looks like the answer is "looks good", please open a tracking issue for this proposed set of methods and point to that in the #[unstable] annotation.

@dbrgn dbrgn force-pushed the trim-on-byte-slices branch 2 times, most recently from c12401f to 08f80df Compare February 15, 2022 23:28
@dbrgn
Copy link
Contributor Author

dbrgn commented Feb 15, 2022

Tracking issue is here: #94035

  • Unstable annotations have been updated: diff
  • Functions are now const using the implementation suggested by @workingjubilee: diff

Co-authored-by: Jubilee Young <workingjubilee@gmail.com>
@workingjubilee
Copy link
Member

Thank you!

Then with that point of bureaucracy formalized, it looks like this has been approved, so!
@bors r=joshtriplett rollup

@bors
Copy link
Contributor

bors commented Feb 17, 2022

📌 Commit f7448a7 has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 17, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 18, 2022
…iplett

core: Implement ASCII trim functions on byte slices

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](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), 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: rust-lang#94035
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 19, 2022
…iplett

core: Implement ASCII trim functions on byte slices

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](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), 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: rust-lang#94035
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 19, 2022
…iplett

core: Implement ASCII trim functions on byte slices

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](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), 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: rust-lang#94035
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 19, 2022
…iplett

core: Implement ASCII trim functions on byte slices

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](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), 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: rust-lang#94035
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 19, 2022
…iplett

core: Implement ASCII trim functions on byte slices

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](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), 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: rust-lang#94035
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 19, 2022
…iplett

core: Implement ASCII trim functions on byte slices

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](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), 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: rust-lang#94035
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 19, 2022
…iplett

core: Implement ASCII trim functions on byte slices

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](https://std-dev-guide.rust-lang.org/feature-lifecycle/new-unstable-features.html), 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: rust-lang#94035
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 20, 2022
…askrgr

Rollup of 14 pull requests

Successful merges:

 - rust-lang#93580 (Stabilize pin_static_ref.)
 - rust-lang#93639 (Release notes for 1.59)
 - rust-lang#93686 (core: Implement ASCII trim functions on byte slices)
 - rust-lang#94002 (rustdoc: Avoid duplicating macros in sidebar)
 - rust-lang#94019 (removing architecture requirements for RustyHermit)
 - rust-lang#94023 (adapt static-nobundle test to use llvm-nm)
 - rust-lang#94091 (Fix rustdoc const computed value)
 - rust-lang#94093 (Fix pretty printing of enums without variants)
 - rust-lang#94097 (Add module-level docs for `rustc_middle::query`)
 - rust-lang#94112 (Optimize char_try_from_u32)
 - rust-lang#94113 (document rustc_middle::mir::Field)
 - rust-lang#94122 (Fix miniz_oxide types showing up in std docs)
 - rust-lang#94142 (rustc_typeck: adopt let else in more places)
 - rust-lang#94146 (Adopt let else in more places)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 575f6c5 into rust-lang:master Feb 20, 2022
@rustbot rustbot added this to the 1.61.0 milestone Feb 20, 2022
@dbrgn dbrgn deleted the trim-on-byte-slices branch March 7, 2022 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants