mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Inline annotations() helper into write_header()
This commit is contained in:
parent
4c8a5b5104
commit
f229c79517
@ -3,19 +3,6 @@ use std::str;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use syn;
|
use syn;
|
||||||
|
|
||||||
fn annotations(generics: &syn::Generics) -> String {
|
|
||||||
if generics.lifetimes.len() < 1 {
|
|
||||||
return String::new();
|
|
||||||
}
|
|
||||||
let mut res = String::new();
|
|
||||||
res.push('<');
|
|
||||||
for lt in &generics.lifetimes {
|
|
||||||
res.push_str(lt.lifetime.ident.as_ref());
|
|
||||||
}
|
|
||||||
res.push('>');
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
|
||||||
fn path_as_identifier(s: &str) -> String {
|
fn path_as_identifier(s: &str) -> String {
|
||||||
let mut res = String::new();
|
let mut res = String::new();
|
||||||
for c in s.chars() {
|
for c in s.chars() {
|
||||||
@ -321,7 +308,15 @@ impl<'a> Generator<'a> {
|
|||||||
|
|
||||||
fn write_header(&mut self, ast: &syn::DeriveInput,
|
fn write_header(&mut self, ast: &syn::DeriveInput,
|
||||||
trait_suffix: Option<&str>) {
|
trait_suffix: Option<&str>) {
|
||||||
let anno = annotations(&ast.generics);
|
let mut anno = String::new();
|
||||||
|
if ast.generics.lifetimes.len() > 0 {
|
||||||
|
anno.push('<');
|
||||||
|
for lt in &ast.generics.lifetimes {
|
||||||
|
anno.push_str(lt.lifetime.ident.as_ref());
|
||||||
|
}
|
||||||
|
anno.push('>');
|
||||||
|
};
|
||||||
|
|
||||||
let name = if trait_suffix.is_some() {
|
let name = if trait_suffix.is_some() {
|
||||||
format!("TraitFrom{}", trait_suffix.unwrap())
|
format!("TraitFrom{}", trait_suffix.unwrap())
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user