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

Lessen the amount of unwrap calls #303

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ impl ExecResizeOptions {
{
for (k, v) in params.iter() {
let key = k.to_string();
let value = serde_json::to_value(v).unwrap();

body.insert(key, value);
if let Ok(value) = serde_json::to_value(v) {
body.insert(key, value);
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ impl NetworkCreateOptions {
{
for (k, v) in params.iter() {
let key = k.to_string();
let value = serde_json::to_value(v).unwrap();

body.insert(key, value);
if let Ok(value) = serde_json::to_value(v) {
body.insert(key, value);
}
}
}
}
Expand Down Expand Up @@ -269,9 +269,9 @@ impl ContainerConnectionOptions {
{
for (k, v) in params.iter() {
let key = k.to_string();
let value = serde_json::to_value(v).unwrap();

body.insert(key, value);
if let Ok(value) = serde_json::to_value(v) {
body.insert(key, value);
}
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,16 @@ impl ServiceListOptionsBuilder {
ServiceFilter::Name(n) => param.insert("name", vec![n.to_string()]),
};
}
// structure is a a json encoded object mapping string keys to a list
// of string values
self.params
.insert("filters", serde_json::to_string(&param).unwrap());
self

if let Ok(structure) = serde_json::to_string(&param) {
// structure is a a json encoded object mapping string keys to a list
// of string values
self.params.insert("filters", structure);
return self;
} else {
// TODO: Handle serde_json::to_string serialization error
panic!();
}
}

pub fn enable_status(&mut self) -> &mut Self {
Expand Down
23 changes: 12 additions & 11 deletions src/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ where

{
let base_path = Path::new(path).canonicalize()?;
// todo: don't unwrap
let mut base_path_str = base_path.to_str().unwrap().to_owned();
let mut base_path_str = String::new();
if let Some(value) = base_path.to_str() {
base_path_str = value.to_owned();
}

if let Some(last) = base_path_str.chars().last() {
if last != MAIN_SEPARATOR {
base_path_str.push(MAIN_SEPARATOR)
Expand All @@ -51,16 +54,14 @@ where

let mut append = |path: &Path| {
let canonical = path.canonicalize()?;
// todo: don't unwrap
let relativized = canonical
.to_str()
.unwrap()
.trim_start_matches(&base_path_str[..]);
if path.is_dir() {
archive.append_dir(Path::new(relativized), &canonical)?
} else {
archive.append_file(Path::new(relativized), &mut File::open(&canonical)?)?
if let Some(relativized) = canonical.to_str() {
if path.is_dir() {
archive.append_dir(Path::new(relativized.trim_start_matches(&base_path_str[..])), &canonical)?
} else {
archive.append_file(Path::new(relativized.trim_start_matches(&base_path_str[..])), &mut File::open(&canonical)?)?
}
}

Ok(())
};
bundle(Path::new(path), &mut append, false)?;
Expand Down