Skip to content

Commit

Permalink
code style enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
softprops committed Sep 9, 2017
1 parent 51751f0 commit 022388e
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 85 deletions.
2 changes: 1 addition & 1 deletion examples/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ extern crate shiplift;

use shiplift::Docker;
use std::env;
use std::io::copy;
use std::fs::OpenOptions;
use std::io::copy;

fn main() {
let docker = Docker::new();
Expand Down
2 changes: 1 addition & 1 deletion examples/networkcreate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate shiplift;

use shiplift::{NetworkCreateOptions, Docker};
use shiplift::{Docker, NetworkCreateOptions};
use std::env;

fn main() {
Expand Down
10 changes: 10 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# keep imports tidy
reorder_imported_names = true
reorder_imports = true
reorder_imports_in_group = true
# there is no try!
use_try_shorthand = true
# don't create rustfmt artifacts
write_mode = "Replace"
# reduce wide load
max_width = 80
118 changes: 90 additions & 28 deletions src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Interfaces for building various structures

use rustc_serialize::json::{self, Json, ToJson};
use self::super::Result;
use rustc_serialize::json::{self, Json, ToJson};
use std::cmp::Eq;
use std::collections::{BTreeMap, HashMap};
use std::iter::Peekable;
use std::hash::Hash;
use std::iter::IntoIterator;
use std::iter::Peekable;
use url::form_urlencoded;

#[derive(Default)]
Expand Down Expand Up @@ -222,14 +222,21 @@ impl ContainerListOptionsBuilder {
ContainerListOptionsBuilder { ..Default::default() }
}

pub fn filter(&mut self, filters: Vec<ContainerFilter>) -> &mut ContainerListOptionsBuilder {
pub fn filter(
&mut self,
filters: Vec<ContainerFilter>,
) -> &mut ContainerListOptionsBuilder {
let mut param = HashMap::new();
for f in filters {
match f {
ContainerFilter::ExitCode(c) => param.insert("exit", vec![c.to_string()]),
ContainerFilter::ExitCode(c) => {
param.insert("exit", vec![c.to_string()])
}
ContainerFilter::Status(s) => param.insert("status", vec![s]),
ContainerFilter::LabelName(n) => param.insert("label", vec![n]),
ContainerFilter::Label(n, v) => param.insert("label", vec![format!("{}={}", n, v)]),
ContainerFilter::Label(n, v) => {
param.insert("label", vec![format!("{}={}", n, v)])
}
};

}
Expand Down Expand Up @@ -278,7 +285,10 @@ impl ToJson for ContainerOptions {

// The HostConfig element gets initialized to an empty object,
// for backward compatibility.
body_members.insert("HostConfig".to_string(), Json::Object(BTreeMap::new()));
body_members.insert(
"HostConfig".to_string(),
Json::Object(BTreeMap::new()),
);

let mut body = Json::Object(body_members);

Expand All @@ -292,8 +302,11 @@ impl ToJson for ContainerOptions {

/// Function to insert a JSON value into a tree where the desired
/// location of the value is given as a path of JSON keys.
fn insert<'a, I, V>(key_path: &mut Peekable<I>, value: &V, parent_node: &mut Json)
where
fn insert<'a, I, V>(
key_path: &mut Peekable<I>,
value: &V,
parent_node: &mut Json,
) where
V: ToJson,
I: Iterator<Item = &'a str>,
{
Expand Down Expand Up @@ -326,8 +339,11 @@ impl ContainerOptions {
Ok(json::encode(&self.to_json())?)
}

pub fn parse_from<'a, K, V>(&self, params: &'a HashMap<K, V>, body: &mut Json)
where
pub fn parse_from<'a, K, V>(
&self,
params: &'a HashMap<K, V>,
body: &mut Json,
) where
&'a HashMap<K, V>: IntoIterator,
K: ToString + Eq + Hash,
V: ToJson,
Expand Down Expand Up @@ -367,7 +383,10 @@ impl ContainerOptionsBuilder {
self
}

pub fn volumes(&mut self, volumes: Vec<&str>) -> &mut ContainerOptionsBuilder {
pub fn volumes(
&mut self,
volumes: Vec<&str>,
) -> &mut ContainerOptionsBuilder {
for v in volumes {
self.params_list
.entry("HostConfig.Binds")
Expand All @@ -387,7 +406,10 @@ impl ContainerOptionsBuilder {
self
}

pub fn extra_hosts(&mut self, hosts: Vec<&str>) -> &mut ContainerOptionsBuilder {
pub fn extra_hosts(
&mut self,
hosts: Vec<&str>,
) -> &mut ContainerOptionsBuilder {
for host in hosts {
self.params_list
.entry("HostConfig.ExtraHosts")
Expand All @@ -398,7 +420,10 @@ impl ContainerOptionsBuilder {
self
}

pub fn volumes_from(&mut self, volumes: Vec<&str>) -> &mut ContainerOptionsBuilder {
pub fn volumes_from(
&mut self,
volumes: Vec<&str>,
) -> &mut ContainerOptionsBuilder {
for volume in volumes {
self.params_list
.entry("HostConfig.VolumesFrom")
Expand All @@ -408,7 +433,10 @@ impl ContainerOptionsBuilder {
self
}

pub fn network_mode(&mut self, network: &str) -> &mut ContainerOptionsBuilder {
pub fn network_mode(
&mut self,
network: &str,
) -> &mut ContainerOptionsBuilder {
if !network.is_empty() {
self.params.insert(
"HostConfig.NetworkMode",
Expand Down Expand Up @@ -436,7 +464,10 @@ impl ContainerOptionsBuilder {
self
}

pub fn entrypoint(&mut self, entrypoint: &str) -> &mut ContainerOptionsBuilder {
pub fn entrypoint(
&mut self,
entrypoint: &str,
) -> &mut ContainerOptionsBuilder {
if !entrypoint.is_empty() {
self.params.insert(
"Entrypoint",
Expand All @@ -446,7 +477,10 @@ impl ContainerOptionsBuilder {
self
}

pub fn capabilities(&mut self, capabilities: Vec<&str>) -> &mut ContainerOptionsBuilder {
pub fn capabilities(
&mut self,
capabilities: Vec<&str>,
) -> &mut ContainerOptionsBuilder {
for c in capabilities {
self.params_list
.entry("HostConfig.CapAdd")
Expand All @@ -469,7 +503,10 @@ impl ContainerOptionsBuilder {
self
}

pub fn log_driver(&mut self, log_driver: &str) -> &mut ContainerOptionsBuilder {
pub fn log_driver(
&mut self,
log_driver: &str,
) -> &mut ContainerOptionsBuilder {
if !log_driver.is_empty() {
self.params.insert(
"HostConfig.LogConfig.Type",
Expand Down Expand Up @@ -571,13 +608,19 @@ impl ExecContainerOptionsBuilder {
}

/// Attach to stdout of the exec command
pub fn attach_stdout(&mut self, stdout: bool) -> &mut ExecContainerOptionsBuilder {
pub fn attach_stdout(
&mut self,
stdout: bool,
) -> &mut ExecContainerOptionsBuilder {
self.params_bool.insert("AttachStdout", stdout);
self
}

/// Attach to stderr of the exec command
pub fn attach_stderr(&mut self, stderr: bool) -> &mut ExecContainerOptionsBuilder {
pub fn attach_stderr(
&mut self,
stderr: bool,
) -> &mut ExecContainerOptionsBuilder {
self.params_bool.insert("AttachStderr", stderr);
self
}
Expand Down Expand Up @@ -665,7 +708,10 @@ impl EventsOptionsBuilder {
self
}

pub fn filter(&mut self, filters: Vec<EventFilter>) -> &mut EventsOptionsBuilder {
pub fn filter(
&mut self,
filters: Vec<EventFilter>,
) -> &mut EventsOptionsBuilder {
let mut param = HashMap::new();
for f in filters {
match f {
Expand All @@ -677,7 +723,10 @@ impl EventsOptionsBuilder {
EventFilter::Network(n) => param.insert("network", vec![n]),
EventFilter::Daemon(n) => param.insert("daemon", vec![n]),
EventFilter::Type(n) => {
param.insert("type", vec![event_filter_type_to_string(n).to_string()])
param.insert(
"type",
vec![event_filter_type_to_string(n).to_string()],
)
}
};

Expand Down Expand Up @@ -809,13 +858,20 @@ impl ImageListOptionsBuilder {
self
}

pub fn filter(&mut self, filters: Vec<ImageFilter>) -> &mut ImageListOptionsBuilder {
pub fn filter(
&mut self,
filters: Vec<ImageFilter>,
) -> &mut ImageListOptionsBuilder {
let mut param = HashMap::new();
for f in filters {
match f {
ImageFilter::Dangling => param.insert("dangling", vec![true.to_string()]),
ImageFilter::Dangling => {
param.insert("dangling", vec![true.to_string()])
}
ImageFilter::LabelName(n) => param.insert("label", vec![n]),
ImageFilter::Label(n, v) => param.insert("label", vec![format!("{}={}", n, v)]),
ImageFilter::Label(n, v) => {
param.insert("label", vec![format!("{}={}", n, v)])
}
};

}
Expand Down Expand Up @@ -925,8 +981,11 @@ impl NetworkCreateOptions {
Ok(json::encode(&self.to_json())?)
}

pub fn parse_from<'a, K, V>(&self, params: &'a HashMap<K, V>, body: &mut BTreeMap<String, Json>)
where
pub fn parse_from<'a, K, V>(
&self,
params: &'a HashMap<K, V>,
body: &mut BTreeMap<String, Json>,
) where
&'a HashMap<K, V>: IntoIterator,
K: ToString + Eq + Hash,
V: ToJson,
Expand Down Expand Up @@ -1010,8 +1069,11 @@ impl ContainerConnectionOptions {
Ok(json::encode(&self.to_json())?)
}

pub fn parse_from<'a, K, V>(&self, params: &'a HashMap<K, V>, body: &mut BTreeMap<String, Json>)
where
pub fn parse_from<'a, K, V>(
&self,
params: &'a HashMap<K, V>,
body: &mut BTreeMap<String, Json>,
) where
&'a HashMap<K, V>: IntoIterator,
K: ToString + Eq + Hash,
V: ToJson,
Expand Down
6 changes: 3 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Representations of various client errors

use std::error::Error as ErrorTrait;
use std::io::Error as IoError;
use std::fmt;
use hyper::Error as HttpError;
use hyper::status::StatusCode;
use rustc_serialize::json::{DecoderError, EncoderError, ParserError};
use std::error::Error as ErrorTrait;
use std::fmt;
use std::io::Error as IoError;

#[derive(Debug)]
pub enum Error {
Expand Down
Loading

0 comments on commit 022388e

Please sign in to comment.