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

address some small and uncontroversial lints #318

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
with:
components: clippy
- uses: actions/checkout@v1
- run: cargo clippy --all-targets -- -D clippy::all
- run: cargo clippy --all-targets

compile:
runs-on: ubuntu-latest
Expand Down
24 changes: 12 additions & 12 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ impl<'docker> Container<'docker> {
psargs: Option<&str>,
) -> Result<Top> {
let mut path = vec![format!("/containers/{}/top", self.id)];
if let Some(ref args) = psargs {
if let Some(args) = psargs {
let encoded = form_urlencoded::Serializer::new(String::new())
.append_pair("ps_args", args)
.finish();
path.push(encoded)
path.push(encoded);
}
self.docker.get_json(&path.join("?")).await
}
Expand All @@ -93,7 +93,7 @@ impl<'docker> Container<'docker> {
) -> impl Stream<Item = Result<tty::TtyChunk>> + Unpin + 'docker {
let mut path = vec![format!("/containers/{}/logs", self.id)];
if let Some(query) = opts.serialize() {
path.push(query)
path.push(query);
}

let stream = Box::pin(self.docker.stream_get(path.join("?")));
Expand Down Expand Up @@ -192,7 +192,7 @@ impl<'docker> Container<'docker> {
.append_pair("t", &w.as_secs().to_string())
.finish();

path.push(encoded)
path.push(encoded);
}
self.docker.post(&path.join("?"), None).await?;
Ok(())
Expand All @@ -210,7 +210,7 @@ impl<'docker> Container<'docker> {
let encoded = form_urlencoded::Serializer::new(String::new())
.append_pair("t", &w.as_secs().to_string())
.finish();
path.push(encoded)
path.push(encoded);
}
self.docker.post(&path.join("?"), None).await?;
Ok(())
Expand All @@ -228,7 +228,7 @@ impl<'docker> Container<'docker> {
let encoded = form_urlencoded::Serializer::new(String::new())
.append_pair("signal", &sig.to_owned())
.finish();
path.push(encoded)
path.push(encoded);
}
self.docker.post(&path.join("?"), None).await?;
Ok(())
Expand Down Expand Up @@ -303,7 +303,7 @@ impl<'docker> Container<'docker> {
) -> Result<()> {
let mut path = vec![format!("/containers/{}", self.id)];
if let Some(query) = opts.serialize() {
path.push(query)
path.push(query);
}
self.docker.delete(&path.join("?")).await?;
Ok(())
Expand Down Expand Up @@ -420,7 +420,7 @@ impl<'docker> Containers<'docker> {
) -> Result<Vec<ContainerInfo>> {
let mut path = vec!["/containers/json".to_owned()];
if let Some(query) = opts.serialize() {
path.push(query)
path.push(query);
}
self.docker
.get_json::<Vec<ContainerInfo>>(&path.join("?"))
Expand Down Expand Up @@ -625,7 +625,7 @@ impl ContainerOptions {
{
for (k, v) in params.iter() {
let key_string = k.to_string();
insert(&mut key_string.split('.').peekable(), v, body)
insert(&mut key_string.split('.').peekable(), v, body);
}
}
}
Expand Down Expand Up @@ -1720,7 +1720,7 @@ mod tests {
.append_pair("filters", r#"{"label":["label1=value","label2"]}"#)
.finish();

assert_eq!(form, options.serialize().unwrap())
assert_eq!(form, options.serialize().unwrap());
}

#[test]
Expand All @@ -1733,7 +1733,7 @@ mod tests {
.append_pair("filters", r#"{"exited":["0"]}"#)
.finish();

assert_eq!(form, options.serialize().unwrap())
assert_eq!(form, options.serialize().unwrap());
}

#[test]
Expand All @@ -1746,7 +1746,7 @@ mod tests {
.append_pair("filters", r#"{"status":["running"]}"#)
.finish();

assert_eq!(form, options.serialize().unwrap())
assert_eq!(form, options.serialize().unwrap());
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ impl<'docker> Image<'docker> {
) -> Result<()> {
let mut path = vec![format!("/images/{}/tag", self.name)];
if let Some(query) = opts.serialize() {
path.push(query)
path.push(query);
}
let _ = self.docker.post(&path.join("?"), None).await?;
self.docker.post(&path.join("?"), None).await?;
Ok(())
}
}
Expand All @@ -113,7 +113,7 @@ impl<'docker> Images<'docker> {
) -> impl Stream<Item = Result<ImageBuildChunk>> + Unpin + 'docker {
let mut endpoint = vec!["/build".to_owned()];
if let Some(query) = opts.serialize() {
endpoint.push(query)
endpoint.push(query);
}

// To not tie the lifetime of `opts` to the 'stream, we do the tarring work outside of the
Expand Down Expand Up @@ -578,7 +578,7 @@ impl BuildOptionsBuilder {
{
BuildOptionsBuilder {
path: path.into(),
..Default::default()
..Self::default()
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all)]

//! Shiplift is a multi-transport utility for maneuvering [docker](https://www.docker.com/) containers
//!
//! # examples
Expand Down
4 changes: 2 additions & 2 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'docker> Service<'docker> {
) -> impl Stream<Item = Result<tty::TtyChunk>> + Unpin + 'docker {
let mut path = vec![format!("/services/{}/logs", self.name)];
if let Some(query) = opts.serialize() {
path.push(query)
path.push(query);
}

let stream = Box::pin(self.docker.stream_get(path.join("?")));
Expand Down Expand Up @@ -343,7 +343,7 @@ impl ServiceOptionsBuilder {
pub fn build(&mut self) -> Result<ServiceOptions> {
let params = std::mem::take(&mut self.params);
let mut new_params = HashMap::new();
for (k, v) in params.into_iter() {
for (k, v) in params {
new_params.insert(k, v?);
}
Ok(ServiceOptions {
Expand Down
10 changes: 5 additions & 5 deletions src/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ where
{
if fs::metadata(dir)?.is_dir() {
if bundle_dir {
f(&dir)?;
f(dir)?;
}
for entry in fs::read_dir(dir)? {
let entry = entry?;
if fs::metadata(entry.path())?.is_dir() {
bundle(&entry.path(), f, true)?;
} else {
f(&entry.path().as_path())?;
f(entry.path().as_path())?;
}
}
}
Expand All @@ -45,7 +45,7 @@ where
let mut base_path_str = base_path.to_str().unwrap().to_owned();
if let Some(last) = base_path_str.chars().last() {
if last != MAIN_SEPARATOR {
base_path_str.push(MAIN_SEPARATOR)
base_path_str.push(MAIN_SEPARATOR);
}
}

Expand All @@ -57,9 +57,9 @@ where
.unwrap()
.trim_start_matches(&base_path_str[..]);
if path.is_dir() {
archive.append_dir(Path::new(relativized), &canonical)?
archive.append_dir(Path::new(relativized), &canonical)?;
} else {
archive.append_file(Path::new(relativized), &mut File::open(&canonical)?)?
archive.append_file(Path::new(relativized), &mut File::open(&canonical)?)?;
}
Ok(())
};
Expand Down
2 changes: 1 addition & 1 deletion src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl Transport {
let mut req = req.header(header::HOST, "");

if let Some(h) = headers {
for (k, v) in h.into_iter() {
for (k, v) in h {
req = req.header(k, v);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ where

let mut data = vec![0u8; data_length as usize];

if stream.read_exact(&mut data).await.is_err() {
return None;
}
stream.read_exact(&mut data).await.ok()?;

let chunk = match header_bytes[0] {
0 => TtyChunk::StdIn(data),
Expand Down
6 changes: 3 additions & 3 deletions src/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ mod test {

assert_eq!(volume_info.driver, Some("my_driver".to_string()));
assert_eq!(volume_info.name, None);
assert_eq!(volume_info.driver_opts, None)
assert_eq!(volume_info.driver_opts, None);
}

#[test]
fn test_volumecreateoptionsbuilder_driver_opts() {
let opts: HashMap<&str, &str> = [("option", "value")].iter().cloned().collect();
let opts: HashMap<&str, &str> = [("option", "value")].iter().copied().collect();
let volume = VolumeCreateOptions::builder()
.driver("my_driver", Some(&opts))
.build();
Expand All @@ -252,6 +252,6 @@ mod test {

assert_eq!(volume_info.driver, Some("my_driver".to_string()));
assert_eq!(volume_info.name, None);
assert_eq!(volume_info.driver_opts, Some(driver_options))
assert_eq!(volume_info.driver_opts, Some(driver_options));
}
}