mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 14:31:36 +00:00
Replace &PathBuf
with &Path
PathBuf is to String like Path is to str, so `&PathBuf` is a pointer to a pointer. Clippy does not likes that.
This commit is contained in:
parent
86fd2f4f8b
commit
bb7c60ece5
@ -46,7 +46,7 @@ fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
|
|||||||
|
|
||||||
let mut parsed = HashMap::new();
|
let mut parsed = HashMap::new();
|
||||||
for (path, src) in &sources {
|
for (path, src) in &sources {
|
||||||
parsed.insert(path, parse(src, input.syntax)?);
|
parsed.insert(path.as_path(), parse(src, input.syntax)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut contexts = HashMap::new();
|
let mut contexts = HashMap::new();
|
||||||
@ -54,7 +54,7 @@ fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
|
|||||||
contexts.insert(*path, Context::new(input.config, path, nodes)?);
|
contexts.insert(*path, Context::new(input.config, path, nodes)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ctx = &contexts[&input.path];
|
let ctx = &contexts[input.path.as_path()];
|
||||||
let heritage = if !ctx.blocks.is_empty() || ctx.extends.is_some() {
|
let heritage = if !ctx.blocks.is_empty() || ctx.extends.is_some() {
|
||||||
Some(Heritage::new(ctx, &contexts))
|
Some(Heritage::new(ctx, &contexts))
|
||||||
} else {
|
} else {
|
||||||
@ -62,7 +62,7 @@ fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if input.print == Print::Ast || input.print == Print::All {
|
if input.print == Print::Ast || input.print == Print::All {
|
||||||
eprintln!("{:?}", parsed[&input.path]);
|
eprintln!("{:?}", parsed[input.path.as_path()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = generator::generate(&input, &contexts, heritage.as_ref(), INTEGRATIONS)?;
|
let code = generator::generate(&input, &contexts, heritage.as_ref(), INTEGRATIONS)?;
|
||||||
|
@ -9,24 +9,24 @@ use proc_macro2::Span;
|
|||||||
use quote::{quote, ToTokens};
|
use quote::{quote, ToTokens};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::Path;
|
||||||
use std::{cmp, hash, mem, str};
|
use std::{cmp, hash, mem, str};
|
||||||
|
|
||||||
pub fn generate<S: std::hash::BuildHasher>(
|
pub fn generate<S: std::hash::BuildHasher>(
|
||||||
input: &TemplateInput<'_>,
|
input: &TemplateInput<'_>,
|
||||||
contexts: &HashMap<&PathBuf, Context<'_>, S>,
|
contexts: &HashMap<&Path, Context<'_>, S>,
|
||||||
heritage: Option<&Heritage<'_>>,
|
heritage: Option<&Heritage<'_>>,
|
||||||
integrations: Integrations,
|
integrations: Integrations,
|
||||||
) -> Result<String, CompileError> {
|
) -> Result<String, CompileError> {
|
||||||
Generator::new(input, contexts, heritage, integrations, MapChain::new())
|
Generator::new(input, contexts, heritage, integrations, MapChain::new())
|
||||||
.build(&contexts[&input.path])
|
.build(&contexts[input.path.as_path()])
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Generator<'a, S: std::hash::BuildHasher> {
|
struct Generator<'a, S: std::hash::BuildHasher> {
|
||||||
// The template input state: original struct AST and attributes
|
// The template input state: original struct AST and attributes
|
||||||
input: &'a TemplateInput<'a>,
|
input: &'a TemplateInput<'a>,
|
||||||
// All contexts, keyed by the package-relative template path
|
// All contexts, keyed by the package-relative template path
|
||||||
contexts: &'a HashMap<&'a PathBuf, Context<'a>, S>,
|
contexts: &'a HashMap<&'a Path, Context<'a>, S>,
|
||||||
// The heritage contains references to blocks and their ancestry
|
// The heritage contains references to blocks and their ancestry
|
||||||
heritage: Option<&'a Heritage<'a>>,
|
heritage: Option<&'a Heritage<'a>>,
|
||||||
// What integrations need to be generated
|
// What integrations need to be generated
|
||||||
@ -51,7 +51,7 @@ struct Generator<'a, S: std::hash::BuildHasher> {
|
|||||||
impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
|
impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
|
||||||
fn new<'n>(
|
fn new<'n>(
|
||||||
input: &'n TemplateInput<'_>,
|
input: &'n TemplateInput<'_>,
|
||||||
contexts: &'n HashMap<&'n PathBuf, Context<'n>, S>,
|
contexts: &'n HashMap<&'n Path, Context<'n>, S>,
|
||||||
heritage: Option<&'n Heritage<'_>>,
|
heritage: Option<&'n Heritage<'_>>,
|
||||||
integrations: Integrations,
|
integrations: Integrations,
|
||||||
locals: MapChain<'n, &'n str, LocalMeta>,
|
locals: MapChain<'n, &'n str, LocalMeta>,
|
||||||
@ -134,7 +134,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
|
|||||||
// Skip the fake path of templates defined in rust source.
|
// Skip the fake path of templates defined in rust source.
|
||||||
let path_is_valid = match self.input.source {
|
let path_is_valid = match self.input.source {
|
||||||
Source::Path(_) => true,
|
Source::Path(_) => true,
|
||||||
Source::Source(_) => *path != &self.input.path,
|
Source::Source(_) => path != &self.input.path,
|
||||||
};
|
};
|
||||||
if path_is_valid {
|
if path_is_valid {
|
||||||
let path = path.to_str().unwrap();
|
let path = path.to_str().unwrap();
|
||||||
@ -669,7 +669,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
|
|||||||
let path = ctx.imports.get(s).ok_or_else(|| {
|
let path = ctx.imports.get(s).ok_or_else(|| {
|
||||||
CompileError::String(format!("no import found for scope '{}'", s))
|
CompileError::String(format!("no import found for scope '{}'", s))
|
||||||
})?;
|
})?;
|
||||||
let mctx = self.contexts.get(path).ok_or_else(|| {
|
let mctx = self.contexts.get(path.as_path()).ok_or_else(|| {
|
||||||
CompileError::String(format!("context for '{:?}' not found", path))
|
CompileError::String(format!("context for '{:?}' not found", path))
|
||||||
})?;
|
})?;
|
||||||
(
|
(
|
||||||
|
@ -12,7 +12,7 @@ pub struct Heritage<'a> {
|
|||||||
impl Heritage<'_> {
|
impl Heritage<'_> {
|
||||||
pub fn new<'n, S: std::hash::BuildHasher>(
|
pub fn new<'n, S: std::hash::BuildHasher>(
|
||||||
mut ctx: &'n Context<'n>,
|
mut ctx: &'n Context<'n>,
|
||||||
contexts: &'n HashMap<&'n PathBuf, Context<'n>, S>,
|
contexts: &'n HashMap<&'n Path, Context<'n>, S>,
|
||||||
) -> Heritage<'n> {
|
) -> Heritage<'n> {
|
||||||
let mut blocks: BlockAncestry<'n> = ctx
|
let mut blocks: BlockAncestry<'n> = ctx
|
||||||
.blocks
|
.blocks
|
||||||
@ -21,7 +21,7 @@ impl Heritage<'_> {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
while let Some(ref path) = ctx.extends {
|
while let Some(ref path) = ctx.extends {
|
||||||
ctx = &contexts[&path];
|
ctx = &contexts[path.as_path()];
|
||||||
for (name, def) in &ctx.blocks {
|
for (name, def) in &ctx.blocks {
|
||||||
blocks.entry(name).or_insert_with(Vec::new).push((ctx, def));
|
blocks.entry(name).or_insert_with(Vec::new).push((ctx, def));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user