diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-08-07 15:37:51 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-09-07 17:32:16 +0100 |
commit | b443c533f9e5a0bdbf8b380a8d7d59e46c28858b (patch) | |
tree | fe01f78e107ca092a3d13875ddff704c6ec2afce /src/resource.rs | |
parent | 1afd692bacf6c95d5897d4af74f6f2d4f8b91c1f (diff) | |
download | subplot-b443c533f9e5a0bdbf8b380a8d7d59e46c28858b.tar.gz |
chore: Unwind global template name
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/resource.rs')
-rw-r--r-- | src/resource.rs | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/resource.rs b/src/resource.rs index 0149cd7..bd6fc34 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -45,7 +45,6 @@ lazy_static! { let ret = Vec::new(); Mutex::new(ret) }; - static ref TEMPLATE_NAME: Mutex<Option<String>> = Mutex::new(None); } static EMBEDDED_FILES: &[(&str, &[u8])] = include!(concat!(env!("OUT_DIR"), "/embedded_files.inc")); @@ -63,11 +62,6 @@ fn add_search_path<P: AsRef<Path>>(path: P) { .push(path.as_ref().into()); } -/// Set the template name, for use in searching for content... -pub fn set_template(template: &str) { - *TEMPLATE_NAME.lock().expect("Unable to lock TEMPLATE_NAME") = Some(template.to_string()); -} - /// Open a file for reading, honouring search paths established during /// startup, and falling back to potentially embedded file content. /// @@ -79,13 +73,12 @@ pub fn set_template(template: &str) { /// /// Then we repeat all the above, inserting the template name in the subpath /// too. -fn open<P: AsRef<Path>>(subpath: P) -> io::Result<Box<dyn Read>> { +fn open<P: AsRef<Path>>(subpath: P, template: Option<&str>) -> io::Result<Box<dyn Read>> { let subpath = subpath.as_ref(); match internal_open(subpath) { Ok(r) => Ok(r), Err(e) => { - let template = TEMPLATE_NAME.lock().expect("Unable to lock TEMPLATE_NAME"); - if let Some(templ) = template.as_deref() { + if let Some(templ) = template { let subpath = Path::new(templ).join(subpath); match internal_open(&subpath) { Ok(r) => Ok(r), @@ -136,8 +129,8 @@ fn internal_open(subpath: &Path) -> io::Result<Box<dyn Read>> { /// Read a file, honouring search paths established during startup, and /// falling back to potentially embedded file content -pub fn read_as_string<P: AsRef<Path>>(subpath: P) -> io::Result<String> { - let mut f = open(subpath)?; +pub fn read_as_string<P: AsRef<Path>>(subpath: P, template: Option<&str>) -> io::Result<String> { + let mut f = open(subpath, template)?; let mut ret = String::with_capacity(8192); f.read_to_string(&mut ret)?; Ok(ret) |