diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2022-02-03 14:55:33 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-02-03 18:09:55 +0100 |
commit | 2d457f54f50de8a9430f1e6e3da42244957911d1 (patch) | |
tree | f4c95ace64ebe9befbb13fbe5ca0c84461d8f416 /askama_shared/src/generator.rs | |
parent | a480c25efe8ddc9c0d6a6a9e3c990ce730c315e4 (diff) | |
download | askama-2d457f54f50de8a9430f1e6e3da42244957911d1.tar.gz askama-2d457f54f50de8a9430f1e6e3da42244957911d1.tar.bz2 askama-2d457f54f50de8a9430f1e6e3da42244957911d1.zip |
Replace custom Cow with actual Cow
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r-- | askama_shared/src/generator.rs | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index daf22ae..924d747 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -665,27 +665,25 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { return self.write_block(buf, None, ws); } - let (def, own_ctx) = if let Some(s) = scope { - let path = ctx.imports.get(s).ok_or_else(|| { - CompileError::String(format!("no import found for scope '{}'", s)) - })?; - let mctx = self.contexts.get(path.as_path()).ok_or_else(|| { - CompileError::String(format!("context for '{:?}' not found", path)) - })?; - ( - mctx.macros.get(name).ok_or_else(|| { - CompileError::String(format!("macro '{}' not found in scope '{}'", name, s)) - })?, - mctx, - ) - } else { - ( - ctx.macros + let (def, own_ctx) = + if let Some(s) = scope { + let path = ctx.imports.get(s).ok_or_else(|| { + CompileError::from(format!("no import found for scope {:?}", s)) + })?; + let mctx = self.contexts.get(path.as_path()).ok_or_else(|| { + CompileError::from(format!("context for {:?} not found", path)) + })?; + let def = mctx.macros.get(name).ok_or_else(|| { + CompileError::from(format!("macro {:?} not found in scope {:?}", name, s)) + })?; + (def, mctx) + } else { + let def = ctx + .macros .get(name) - .ok_or_else(|| CompileError::String(format!("macro '{}' not found", name)))?, - ctx, - ) - }; + .ok_or_else(|| CompileError::from(format!("macro {:?} not found", name)))?; + (def, ctx) + }; self.flush_ws(ws); // Cannot handle_ws() here: whitespace from macro definition comes first self.locals.push(); @@ -698,7 +696,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { let mut is_first_variable = true; for (i, arg) in def.args.iter().enumerate() { let expr = args.get(i).ok_or_else(|| { - CompileError::String(format!("macro '{}' takes more than {} arguments", name, i)) + CompileError::from(format!("macro {:?} takes more than {} arguments", name, i)) })?; match expr { @@ -900,7 +898,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { let heritage = self .heritage .as_ref() - .ok_or(CompileError::Static("no block ancestors available"))?; + .ok_or_else(|| CompileError::from("no block ancestors available"))?; let (ctx, def) = heritage.blocks[cur.0].get(cur.1).ok_or_else(|| { CompileError::from(match name { None => format!("no super() block found for block '{}'", cur.0), @@ -1170,7 +1168,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { .escapers .iter() .find_map(|(escapers, escaper)| escapers.contains(name).then(|| escaper)) - .ok_or(CompileError::Static("invalid escaper for escape filter"))?, + .ok_or_else(|| CompileError::from("invalid escaper for escape filter"))?, None => self.input.escaper, }; buf.write("::askama::filters::escape("); |