aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) }
}