aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Hoeppner2014-11-30 19:31:29 +0100
committerTill Hoeppner2014-11-30 19:31:29 +0100
commitd1b8aba953fdfdee82ac3f30a6c6c0de1f933dc6 (patch)
tree820318279227bfc559f50e4ca97037669f45c893
parent042f7414c229d1c7f66aef24faa92defb91a78cf (diff)
downloadsersve-d1b8aba953fdfdee82ac3f30a6c6c0de1f933dc6.tar.gz
sersve-d1b8aba953fdfdee82ac3f30a6c6c0de1f933dc6.tar.xz
sersve-d1b8aba953fdfdee82ac3f30a6c6c0de1f933dc6.zip
No transmuting, and lto
-rw-r--r--Cargo.toml3
-rw-r--r--src/sersve.rs11
2 files changed, 10 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 566a4d4..a7095d6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,6 +4,9 @@ name = "sersve"
version = "0.0.1"
authors = ["Till Hoeppner <till@hoeppner.ws>"]
+[profile.release]
+lto = true
+
[[bin]]
name = "sersve"
path = "src/sersve.rs"
diff --git a/src/sersve.rs b/src/sersve.rs
index e7e39e2..bda04c6 100644
--- a/src/sersve.rs
+++ b/src/sersve.rs
@@ -90,15 +90,17 @@ fn size_with_unit(mut size: u64) -> String {
format!("{}.{} {}", size, frac, UNITS[index])
}
-fn render(template: Template, root: Path, dir: Path, files: Vec<Path>, filter: Option<Regex>) -> String {
- let data = MapBuilder::new()
+fn render<'a>(template: Template, root: Path, dir: Path, files: Vec<Path>, filter: Option<Regex>) -> String {
+ let data = MapBuilder::<'a>::new()
.insert_str(KEY_TITLE, dir.display().as_cow().into_owned())
- .insert_vec(KEY_CONTENT, |mut vec: VecBuilder| {
+ .insert_vec(KEY_CONTENT, |mut vec: VecBuilder<'a>| {
let item = |map: MapBuilder, url: &Path, size: u64, name: String| {
map.insert(KEY_URL, &format!("{}", url.display())[]).unwrap()
.insert(KEY_SIZE, &size_with_unit(size)[]).unwrap()
.insert_str(KEY_NAME, name)
};
+
+ // add `..` entry if necessary
let mut up = dir.clone();
up.pop();
if root.is_ancestor_of(&up) {
@@ -113,11 +115,12 @@ fn render(template: Template, root: Path, dir: Path, files: Vec<Path>, filter: O
vec = vec.push_map(|map| item(map, &relative, stat.size, filename.clone()));
}
}
- unsafe { std::mem::transmute(vec) }
+ vec
}).build();
let mut out = Vec::new(); // with_capacity(template.len())
template.render_data(&mut out, &data);
+ // The template should be valid utf8, the filenames might not be
unsafe { String::from_utf8_unchecked(out) }
}