wary/options/transformer/
func.rs1#[cfg(test)]
2mod test {
3 use crate::toolbox::test::*;
4
5 #[test]
6 fn test_func_transformer() {
7 #[allow(clippy::trivially_copy_pass_by_ref)]
8 fn change(_ctx: &(), name: &mut String) {
9 name.clear();
10 name.push_str("hello, world!");
11 }
12
13 #[derive(Wary)]
14 #[wary(crate = "crate")]
15 struct Name {
16 #[transform(func = |ctx: &(), name: &mut String| {
17 name.clear();
18 name.push_str("hello, world!");
19 })]
20 left: String,
21 #[transform(func = change)]
22 right: String,
23 }
24
25 let mut name = Name {
26 left: "HelloWorld".into(),
27 right: "HelloWorld".into(),
28 };
29
30 name.transform(&());
31
32 assert_eq!(name.left, "hello, world!");
33 assert_eq!(name.right, "hello, world!");
34 }
35}