diff options
author | Till Hoeppner | 2014-11-30 19:31:29 +0100 |
---|---|---|
committer | Till Hoeppner | 2014-11-30 19:31:29 +0100 |
commit | d1b8aba953fdfdee82ac3f30a6c6c0de1f933dc6 (patch) | |
tree | 820318279227bfc559f50e4ca97037669f45c893 /src | |
parent | 042f7414c229d1c7f66aef24faa92defb91a78cf (diff) | |
download | sersve-d1b8aba953fdfdee82ac3f30a6c6c0de1f933dc6.tar.gz sersve-d1b8aba953fdfdee82ac3f30a6c6c0de1f933dc6.tar.xz sersve-d1b8aba953fdfdee82ac3f30a6c6c0de1f933dc6.zip |
No transmuting, and lto
Diffstat (limited to 'src')
-rw-r--r-- | src/sersve.rs | 11 |
1 files changed, 7 insertions, 4 deletions
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) } } |