diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2020-12-10 21:33:08 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-10 21:33:08 -0800 |
| commit | 17ec4b8258b3f59ded7b2cfae8484be976c658af (patch) | |
| tree | 78e69a92950080416cb1097e7b28c1b76a692ca4 /compiler/rustc_codegen_llvm/src | |
| parent | 8b9a59cb905f2f22c7de7713e38756b20289e0b9 (diff) | |
| parent | 989edf4a5ffb0944e173ec23cb5614c252e8082e (diff) | |
| download | rust-17ec4b8258b3f59ded7b2cfae8484be976c658af.tar.gz rust-17ec4b8258b3f59ded7b2cfae8484be976c658af.zip | |
Rollup merge of #79809 - Eric-Arellano:split-once, r=matklad
Dogfood `str_split_once()`
Part of https://github.com/rust-lang/rust/issues/74773.
Beyond increased clarity, this fixes some instances of a common confusion with how `splitn(2)` behaves: the first element will always be `Some()`, regardless of the delimiter, and even if the value is empty.
Given this code:
```rust
fn main() {
let val = "...";
let mut iter = val.splitn(2, '=');
println!("Input: {:?}, first: {:?}, second: {:?}", val, iter.next(), iter.next());
}
```
We get:
```
Input: "no_delimiter", first: Some("no_delimiter"), second: None
Input: "k=v", first: Some("k"), second: Some("v")
Input: "=", first: Some(""), second: Some("")
```
Using `str_split_once()` makes more clear what happens when the delimiter is not found.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
