Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created July 13, 2017 20:54
Show Gist options
  • Save alexcrichton/cb2c34e6fbfd3fa9d23c4274215ffbeb to your computer and use it in GitHub Desktop.
Save alexcrichton/cb2c34e6fbfd3fa9d23c4274215ffbeb to your computer and use it in GitHub Desktop.
diff --git a/src/client.rs b/src/client.rs
index 3fb7f56..9740132 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -433,7 +433,7 @@ impl Client {
// // private
/// Constructs the full URL for an API call.
- fn build_url(&self, member: &Member, path: &str) -> String {
+ fn build_url(member: &Member, path: &str) -> String {
format!("{}v2/keys{}", member.endpoint, path)
}
@@ -505,9 +505,11 @@ impl Client {
query_pairs.insert("waitIndex", format!("{}", options.wait_index.unwrap()));
}
- let result = first_ok(self.members.clone(), |member| {
+ let cloned_client = self.http_client.clone();
+ let key = key.to_string();
+ let result = first_ok(self.members.clone(), move |member| {
let url = Url::parse_with_params(
- &self.build_url(member, key),
+ &Self::build_url(member, &key),
query_pairs.clone(),
).map_err(Error::from).into_future();
@@ -515,8 +517,7 @@ impl Client {
Uri::from_str(url.as_str()).map_err(Error::from).into_future()
});
- let cloned_client = self.http_client.clone();
-
+ let cloned_client = cloned_client.clone();
let response = uri.and_then(move |uri| cloned_client.get(uri).map_err(Error::from));
let result = response.and_then(|response| {
diff --git a/src/error.rs b/src/error.rs
index 7a2bb69..7bf0119 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -60,6 +60,7 @@ impl Display for Error {
Error::NativeTls(ref error) => write!(f, "{}", error),
Error::Serialization(ref error) => write!(f, "{}", error),
Error::NoEndpoints => f.write_str("At least one endpoint is required to create a Client"),
+ _ => panic!(),
}
}
}
@@ -75,6 +76,7 @@ impl StdError for Error {
Error::NativeTls(_) => "an error occurred configuring TLS",
Error::Serialization(_) => "an error occurred deserializing JSON",
Error::NoEndpoints => "at least one endpoint is required to create a Client",
+ _ => panic!(),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment