1use jacquard_common::{CowStr, IntoStatic};
2use jacquard_derive::IntoStatic;
3
4#[derive(IntoStatic)]
5struct SimpleStruct<'a> {
6 name: CowStr<'a>,
7 count: u32,
8}
9
10#[derive(IntoStatic)]
11struct TupleStruct<'a>(CowStr<'a>, u32);
12
13#[derive(IntoStatic)]
14struct UnitStruct;
15
16#[derive(IntoStatic)]
17enum SimpleEnum<'a> {
18 Variant1(CowStr<'a>),
19 Variant2 { name: CowStr<'a>, value: u32 },
20 Unit,
21}
22
23#[test]
24fn test_struct_into_static() {
25 let s = SimpleStruct {
26 name: CowStr::from("test"),
27 count: 42,
28 };
29 let static_s: SimpleStruct<'static> = s.into_static();
30 assert_eq!(static_s.name.as_ref(), "test");
31 assert_eq!(static_s.count, 42);
32}
33
34#[test]
35fn test_tuple_struct_into_static() {
36 let s = TupleStruct(CowStr::from("test"), 42);
37 let static_s: TupleStruct<'static> = s.into_static();
38 assert_eq!(static_s.0.as_ref(), "test");
39 assert_eq!(static_s.1, 42);
40}
41
42#[test]
43fn test_unit_struct_into_static() {
44 let s = UnitStruct;
45 let _static_s: UnitStruct = s.into_static();
46}
47
48#[test]
49fn test_enum_into_static() {
50 let e1 = SimpleEnum::Variant1(CowStr::from("test"));
51 let static_e1: SimpleEnum<'static> = e1.into_static();
52 match static_e1 {
53 SimpleEnum::Variant1(name) => assert_eq!(name.as_ref(), "test"),
54 _ => panic!("wrong variant"),
55 }
56
57 let e2 = SimpleEnum::Variant2 {
58 name: CowStr::from("test"),
59 value: 42,
60 };
61 let static_e2: SimpleEnum<'static> = e2.into_static();
62 match static_e2 {
63 SimpleEnum::Variant2 { name, value } => {
64 assert_eq!(name.as_ref(), "test");
65 assert_eq!(value, 42);
66 }
67 _ => panic!("wrong variant"),
68 }
69
70 let e3 = SimpleEnum::Unit;
71 let static_e3: SimpleEnum<'static> = e3.into_static();
72 match static_e3 {
73 SimpleEnum::Unit => {}
74 _ => panic!("wrong variant"),
75 }
76}