From 510d6ef41fb595eb928453ab5a2080d009a03a67 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Sun, 30 Nov 2014 21:08:27 +0100 Subject: Removed lazy_static from Cargo.toml --- Cargo.lock | 6 ------ Cargo.toml | 7 +++---- src/sersve.rs | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6952856..2cc438b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,6 @@ dependencies = [ "conduit-mime-types 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "iron 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "persistent 0.0.1 (git+https://github.com/iron/persistent)", "rust-mustache 0.3.0 (git+https://github.com/erickt/rust-mustache)", ] @@ -70,11 +69,6 @@ dependencies = [ "url 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "lazy_static" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "mime" version = "0.0.1" diff --git a/Cargo.toml b/Cargo.toml index a7095d6..0436405 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,9 @@ name = "sersve" path = "src/sersve.rs" [dependencies] -iron = "*" -glob = "*" -conduit-mime-types = "*" -lazy_static = "~0.1.1" +iron = "~0.0.5" +glob = "~0.1.0" +conduit-mime-types = "~0.5.0" [dependencies.persistent] git = "https://github.com/iron/persistent" diff --git a/src/sersve.rs b/src/sersve.rs index bda04c6..94a62c8 100644 --- a/src/sersve.rs +++ b/src/sersve.rs @@ -4,15 +4,11 @@ extern crate getopts; extern crate serialize; extern crate iron; extern crate persistent; -extern crate error; extern crate regex; extern crate "conduit-mime-types" as conduit_mime; extern crate mime; extern crate mustache; -#[phase(plugin)] -extern crate lazy_static; - use std::{ str, os }; use std::str::from_str; use std::path::{ Path, GenericPath }; @@ -41,6 +37,8 @@ use persistent::Read; use mustache::{ Template, VecBuilder, MapBuilder }; +use constants::*; + pub mod constants; #[deriving(Send, Clone, Default, Encodable, Decodable)] @@ -58,12 +56,16 @@ impl Assoc> for OptCarrier {} #[deriving(Send, Clone)] struct State { - template: Template + template: Template, + mime_types: Arc } struct StateCarrier; impl Assoc> for StateCarrier {} +const HOST: &'static str = "0.0.0.0"; +const PORT: u16 = 8080; + static UNITS: &'static [&'static str] = &["B", "kB", "MB", "GB", "TB"]; const BRIEF: &'static str = "A minimal directory server, written in Rust with Iron."; @@ -73,10 +75,6 @@ const KEY_URL: &'static str = "url"; const KEY_SIZE: &'static str = "size"; const KEY_NAME: &'static str = "name"; -lazy_static! { - static ref MIME: Types = Types::new().ok().unwrap(); -} - fn size_with_unit(mut size: u64) -> String { let mut frac = 0; let mut index = 0; @@ -142,9 +140,10 @@ fn serve(req: &mut Request) -> IronResult { o.max_size) }; - let template = { + let (template, mime_types) = { let s = req.get::>>().unwrap(); - s.template.clone() + (s.template.clone(), + s.mime_types.clone()) }; let mut path = root.clone(); @@ -167,7 +166,7 @@ fn serve(req: &mut Request) -> IronResult { return html("I don't think you're allowed to do this."); } let mime: Option = path.extension_str() - .map_or(None, |e| MIME.get_mime_type(e)) + .map_or(None, |e| mime_types.get_mime_type(e)) .map_or(None, |m| from_str(m)); if mime.as_ref().is_some() { plain(content[]).map(|r| r.set(ContentType((*mime.as_ref().unwrap()).clone()))) @@ -265,13 +264,14 @@ fn main() { options.filter = matches.opt_str("f").or(options.filter); options.max_size = matches.opt_str("s").and_then(|s| str::from_str(s[])).or(options.max_size); options.template = matches.opt_str("t").or(options.template); - (options.host.clone().unwrap_or("0.0.0.0".into_string()), - options.port.clone().unwrap_or(8080)) + (options.host.clone().unwrap_or(HOST.into_string()), + options.port.clone().unwrap_or(PORT)) }; - let template = mustache::compile_str(options.template.clone().unwrap_or(constants::OPT_TEMPLATE.into_string())[]); + let template = mustache::compile_str(options.template.clone().unwrap_or(OPT_TEMPLATE.into_string())[]); let state = State { - template: template + template: template, + mime_types: Arc::new(Types::new().ok().unwrap()) }; let mut chain = ChainBuilder::new(serve); -- cgit v1.2.3