Skip to content

Commit 62af469

Browse files
author
Stephan Dilly
committed
custom 1.50-compatible split_once
1 parent f5f9437 commit 62af469

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

asyncgit/src/sync/cred.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn git_credential_fill(url: &str) -> Option<BasicAuthCredential> {
112112

113113
let mut res = BasicAuthCredential::default();
114114
for line in output.lines() {
115-
if let Some(tuple) = line.split_once("=") {
115+
if let Some(tuple) = split_once(line, "=") {
116116
if tuple.0 == "username" {
117117
res.username = Some(tuple.1.to_string());
118118
} else if tuple.0 == "password" {
@@ -128,6 +128,18 @@ fn git_credential_fill(url: &str) -> Option<BasicAuthCredential> {
128128
None
129129
}
130130

131+
fn split_once<'a>(
132+
v: &'a str,
133+
splitter: &str,
134+
) -> Option<(&'a str, &'a str)> {
135+
let mut split = v.split(splitter);
136+
137+
let key = split.next();
138+
let val = split.next();
139+
140+
key.zip(val)
141+
}
142+
131143
/// extract credentials from url
132144
pub fn extract_cred_from_url(url: &str) -> BasicAuthCredential {
133145
if let Ok(url) = url::Url::parse(url) {

0 commit comments

Comments
 (0)