Skip to content

Add str::[r]split_once #74707

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

Merged
merged 1 commit into from
Jul 29, 2020
Merged

Add str::[r]split_once #74707

merged 1 commit into from
Jul 29, 2020

Conversation

matklad
Copy link
Member

@matklad matklad commented Jul 24, 2020

This is useful for quick&dirty parsing of key: value config pairs. Used a bunch in Cargo and rust-analyzer:

In theory, once const-generics are done, this functionality could be achieved without a dedicated method with

match s.splitn(delimier, 2).collect_array::<2>() {
  Some([prefix, suffix]) => todo!(),
  None => todo!(),
}

Even in that world, having a dedicated method seems clearer on the intention.

I am not sure about naming -- this is something I've just came up with yesterday, I don't know off the top of my head analogs in other languages.

If T-libs thinks this is a reasonable API to have, I'll open a tracking issue and add more thorough tests.

@rust-highfive
Copy link
Contributor

r? @dtolnay

(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 Jul 24, 2020
@matklad matklad added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2020
@matklad matklad force-pushed the split_once branch 3 times, most recently from d520bab to 4a7b4df Compare July 24, 2020 08:14
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks plausible to me. Could you make a tracking issue please?

@matklad matklad mentioned this pull request Jul 26, 2020
4 tasks
@matklad matklad force-pushed the split_once branch 2 times, most recently from 91b38b0 to bb2687d Compare July 26, 2020 11:15
@matklad matklad added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 26, 2020
@matklad
Copy link
Member Author

matklad commented Jul 26, 2020

tests&tracking issue added!

@matklad matklad closed this Jul 26, 2020
@matklad matklad reopened this Jul 26, 2020
@dtolnay
Copy link
Member

dtolnay commented Jul 26, 2020

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 26, 2020

📌 Commit bb2687d has been approved by dtolnay

@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 Jul 26, 2020
Manishearth added a commit to Manishearth/rust that referenced this pull request Jul 27, 2020
Add str::[r]split_once

This is useful for quick&dirty parsing of key: value config pairs. Used a bunch in Cargo and rust-analyzer:

* https://github.com/rust-lang/cargo/search?q=splitn%282&unscoped_q=splitn%282
* https://github.com/rust-analyzer/rust-analyzer/search?q=split_delim&unscoped_q=split_delim

In theory, once const-generics are done, this functionality could be achieved without a dedicated method with

```rust
match s.splitn(delimier, 2).collect_array::<2>() {
  Some([prefix, suffix]) => todo!(),
  None => todo!(),
}
```

Even in that world, having a dedicated method seems clearer on the intention.

I am not sure about naming -- this is something I've just came up with yesterday, I don't know off the top of my head analogs in other languages.

If T-libs thinks this is a reasonable API to have, I'll open a tracking issue and add more thorough tests.
@bors
Copy link
Collaborator

bors commented Jul 27, 2020

⌛ Testing commit bb2687d with merge d1b9d490b3374c4af4239be2875a7ca4f3a02b67...

@bors
Copy link
Collaborator

bors commented Jul 27, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 27, 2020
@bors
Copy link
Collaborator

bors commented Jul 28, 2020

☔ The latest upstream changes (presumably #73265) made this pull request unmergeable. Please resolve the merge conflicts.

This is useful for quick&dirty parsing of key: value config pairs
@matklad
Copy link
Member Author

matklad commented Jul 28, 2020

Rebased!

Given that the failure seems completely unrelated, I am going to

@bors r=dtolnay

@bors
Copy link
Collaborator

bors commented Jul 28, 2020

📌 Commit 6e9dc7d has been approved by dtolnay

@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 Jul 28, 2020
@bors
Copy link
Collaborator

bors commented Jul 28, 2020

⌛ Testing commit 6e9dc7d with merge 1c984308eca9a30ec54bed3d3edcbb179a7788ab...

@bors
Copy link
Collaborator

bors commented Jul 28, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 28, 2020
@matklad
Copy link
Member Author

matklad commented Jul 28, 2020

A different spurious error:

   Downloaded cortex-m-rt v0.6.11
warning: spurious network error (2 tries remaining): failed to get 200 response from `https://crates.io/api/v1/crates/as-slice/0.1.2/download`, got 502
warning: spurious network error (1 tries remaining): failed to get 200 response from `https://crates.io/api/v1/crates/as-slice/0.1.2/download`, got 502
error: failed to download from `https://crates.io/api/v1/crates/as-slice/0.1.2/download`

@bors retry

@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 Jul 28, 2020
@bors
Copy link
Collaborator

bors commented Jul 28, 2020

⌛ Testing commit 6e9dc7d with merge 8725668584b02dce2fd223aed0dd53c1eedc4a57...

@bors
Copy link
Collaborator

bors commented Jul 28, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 28, 2020
@matklad
Copy link
Member Author

matklad commented Jul 28, 2020

Hm, the same spurious network error:

  Downloaded opaque-debug v0.2.3
warning: spurious network error (2 tries remaining): failed to get 200 response from `https://crates.io/api/v1/crates/handlebars/3.0.1/download`, got 502
warning: spurious network error (1 tries remaining): failed to get 200 response from `https://crates.io/api/v1/crates/handlebars/3.0.1/download`, got 502
error: failed to download from `https://crates.io/api/v1/crates/handlebars/3.0.1/download`

I guess crates.io is not feeling great today?

@matklad
Copy link
Member Author

matklad commented Jul 28, 2020

Ok, lets try this again

@bors retry

@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 Jul 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 29, 2020
Rollup of 8 pull requests

Successful merges:

 - rust-lang#74266 (Clean up E0720 explanation)
 - rust-lang#74671 (add const generics array coercion test)
 - rust-lang#74707 (Add str::[r]split_once)
 - rust-lang#74814 (Fix RefUnwindSafe & UnwinsSafe impls for lazy::SyncLazy)
 - rust-lang#74859 (Update outdated readme)
 - rust-lang#74864 (ayu theme: Change doccomment color to `#a1ac88`)
 - rust-lang#74872 (Enable to ping RISC-V group via triagebot)
 - rust-lang#74891 (handle ConstEquate in rustdoc)

Failed merges:

r? @ghost
@bors bors merged commit 6968b75 into rust-lang:master Jul 29, 2020
@matklad matklad deleted the split_once branch July 29, 2020 06:56
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants