1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
use askama::Template;
#[derive(Template)]
#[template(source = "{% let (a, b, c) = v %}{{a}}{{b}}{{c}}", ext = "txt")]
struct LetDestructoringTuple {
v: (i32, i32, i32),
}
#[test]
fn test_let_destruct_tuple() {
let t = LetDestructoringTuple { v: (1, 2, 3) };
assert_eq!(t.render().unwrap(), "123");
}
struct UnnamedStruct(i32, i32, i32);
#[derive(Template)]
#[template(
source = "{% let UnnamedStruct(a, b, c) = v %}{{a}}{{b}}{{c}}",
ext = "txt"
)]
struct LetDestructoringUnnamedStruct {
v: UnnamedStruct,
}
#[test]
fn test_let_destruct_unnamed_struct() {
let t = LetDestructoringUnnamedStruct {
v: UnnamedStruct(1, 2, 3),
};
assert_eq!(t.render().unwrap(), "123");
}
#[derive(Template)]
#[template(
source = "{% let UnnamedStruct(a, b, c) = v %}{{a}}{{b}}{{c}}",
ext = "txt"
)]
struct LetDestructoringUnnamedStructRef<'a> {
v: &'a UnnamedStruct,
}
#[test]
fn test_let_destruct_unnamed_struct_ref() {
let v = UnnamedStruct(1, 2, 3);
let t = LetDestructoringUnnamedStructRef { v: &v };
assert_eq!(t.render().unwrap(), "123");
}
struct NamedStruct {
a: i32,
b: i32,
c: i32,
}
#[derive(Template)]
#[template(
source = "{% let NamedStruct { a, b: d, c } = v %}{{a}}{{d}}{{c}}",
ext = "txt"
)]
struct LetDestructoringNamedStruct {
v: NamedStruct,
}
#[test]
fn test_let_destruct_named_struct() {
let t = LetDestructoringNamedStruct {
v: NamedStruct { a: 1, b: 2, c: 3 },
};
assert_eq!(t.render().unwrap(), "123");
}
#[derive(Template)]
#[template(
source = "{% let NamedStruct { a, b: d, c } = v %}{{a}}{{d}}{{c}}",
ext = "txt"
)]
struct LetDestructoringNamedStructRef<'a> {
v: &'a NamedStruct,
}
#[test]
fn test_let_destruct_named_struct_ref() {
let v = NamedStruct { a: 1, b: 2, c: 3 };
let t = LetDestructoringNamedStructRef { v: &v };
assert_eq!(t.render().unwrap(), "123");
}
mod some {
pub mod path {
pub struct Struct<'a>(pub &'a str);
}
}
#[derive(Template)]
#[template(source = "{% let some::path::Struct(v) = v %}{{v}}", ext = "txt")]
struct LetDestructoringWithPath<'a> {
v: some::path::Struct<'a>,
}
#[test]
fn test_let_destruct_with_path() {
let t = LetDestructoringWithPath {
v: some::path::Struct("hello"),
};
assert_eq!(t.render().unwrap(), "hello");
}
#[derive(Template)]
#[template(source = "{% let some::path::Struct with (v) = v %}{{v}}", ext = "txt")]
struct LetDestructoringWithPathAndWithKeyword<'a> {
v: some::path::Struct<'a>,
}
#[test]
fn test_let_destruct_with_path_and_with_keyword() {
let t = LetDestructoringWithPathAndWithKeyword {
v: some::path::Struct("hello"),
};
assert_eq!(t.render().unwrap(), "hello");
}
|