Minor cleanup of nested match/if let statements into using and_then().
This commit is contained in:
parent
8bd48a09a6
commit
276169e43d
@ -38,24 +38,7 @@ fn download_into(dir: &str, file_title: &str, url: &str) -> Result<String> {
|
|||||||
ct_len.map(|x| info!("File Lenght: {}", x));
|
ct_len.map(|x| info!("File Lenght: {}", x));
|
||||||
ct_type.map(|x| info!("Content Type: {}", x));
|
ct_type.map(|x| info!("Content Type: {}", x));
|
||||||
|
|
||||||
// This could be prettier.
|
let ext = get_ext(ct_type.cloned()).unwrap_or(String::from("unkown"));
|
||||||
// Determine the file extension from the http content-type header.
|
|
||||||
let ext = if let Some(t) = ct_type {
|
|
||||||
let mime = mime_guess::get_extensions(t.type_().as_ref(), t.subtype().as_ref());
|
|
||||||
if let Some(m) = mime {
|
|
||||||
if m.contains(&t.subtype().as_ref()) {
|
|
||||||
t.subtype().as_ref().to_string()
|
|
||||||
} else {
|
|
||||||
m.first().unwrap().to_string()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error!("Unkown mime type. {}", t);
|
|
||||||
"unkown".to_string()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error!("Unkown mime type.");
|
|
||||||
"unkown".to_string()
|
|
||||||
};
|
|
||||||
info!("Extension: {}", ext);
|
info!("Extension: {}", ext);
|
||||||
|
|
||||||
// Construct a temp file to save desired content.
|
// Construct a temp file to save desired content.
|
||||||
@ -74,6 +57,19 @@ fn download_into(dir: &str, file_title: &str, url: &str) -> Result<String> {
|
|||||||
Ok(target)
|
Ok(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine the file extension from the http content-type header.
|
||||||
|
fn get_ext(content: Option<ContentType>) -> Option<String> {
|
||||||
|
let cont = content.clone()?;
|
||||||
|
content.and_then(|c| mime_guess::get_extensions(c.type_().as_ref(), c.subtype().as_ref()))
|
||||||
|
.and_then(|c| {
|
||||||
|
if c.contains(&cont.subtype().as_ref()) {
|
||||||
|
Some(cont.subtype().as_ref().to_string())
|
||||||
|
} else {
|
||||||
|
Some(c.first().unwrap().to_string())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Write unit-tests.
|
// TODO: Write unit-tests.
|
||||||
/// Handles the I/O of fetching a remote file and saving into a Buffer and A File.
|
/// Handles the I/O of fetching a remote file and saving into a Buffer and A File.
|
||||||
fn save_io(file: &str, resp: &mut reqwest::Response, content_lenght: Option<u64>) -> Result<()> {
|
fn save_io(file: &str, resp: &mut reqwest::Response, content_lenght: Option<u64>) -> Result<()> {
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
// use gdk_pixbuf::Pixbuf;
|
|
||||||
|
|
||||||
// use diesel::associations::Identifiable;
|
|
||||||
use hammond_data::Podcast;
|
use hammond_data::Podcast;
|
||||||
|
|
||||||
use widgets::podcast::PodcastWidget;
|
use widgets::podcast::PodcastWidget;
|
||||||
@ -89,6 +87,7 @@ fn replace_podcasts(stack: >k::Stack, pop: &PopulatedView) {
|
|||||||
// old.destroy();
|
// old.destroy();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn show_widget(stack: >k::Stack) {
|
pub fn show_widget(stack: >k::Stack) {
|
||||||
stack.set_visible_child_name("widget")
|
stack.set_visible_child_name("widget")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user