Skip to content

Commit

Permalink
clean imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Nov 9, 2024
1 parent 01c72b7 commit cd2e076
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/controller/views/engines.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::BorrowMut, fs, path::Path};
use std::path::Path;

use serde::Serialize;

Expand Down Expand Up @@ -60,33 +60,16 @@ impl TeraView {

impl ViewRenderer for TeraView {
fn render<S: Serialize>(&self, key: &str, data: S) -> Result<String> {
#[cfg(debug_assertions)]
use std::borrow::BorrowMut;

let context = tera::Context::from_serialize(data)?;

// NOTE: this supports full reload of template for every render request.
// it means that you will see refreshed content without rebuild and rerun
// of the app.
// the code here is required, since Tera has no "build every time your render"
// mode, which would have been better.
// we minimize risk by flagging this in debug (development) builds only
// for now we leave this commented out, we propose people use `cargo-watch`
// we want to delay using un__safe as much as possible.
/*
#[cfg(debug_assertions)]
{
let ptr = std::ptr::addr_of!(self.tera);
let mut_ptr = ptr.cast_mut();
// fix this keyword
un__safe {
let tera = &mut *mut_ptr;
tera.full_reload()?;
}
}
*/
#[cfg(debug_assertions)]
tracing::debug!(key = key, "Tera rendering in non-optimized debug mode");
#[cfg(debug_assertions)]
return Ok(self.tera.lock().expect("lock").borrow_mut().render_str(
&fs::read_to_string(Path::new(VIEWS_DIR).join(key))?,
&std::fs::read_to_string(Path::new(VIEWS_DIR).join(key))?,
&context,
)?);

Expand Down

0 comments on commit cd2e076

Please sign in to comment.