Skip to content

Commit 5680bad

Browse files
committed
feat: v1.13.1
1 parent a4489bb commit 5680bad

File tree

8 files changed

+759
-298
lines changed

8 files changed

+759
-298
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lombok-macros"
3-
version = "1.12.2"
3+
version = "1.13.1"
44
edition = "2024"
55
authors = ["root@ltpp.vip"]
66
license = "MIT"

debug/src/main.rs

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,86 @@ use lombok_macros::*;
44
use std::fmt::Debug;
55

66
#[derive(Data, Debug, Clone, DisplayDebugFormat)]
7-
struct LombokTest<'a, 'b, T: Clone>
8-
where
9-
T: Debug,
10-
{
7+
struct LombokTest<'a, T: Clone + Debug> {
118
#[get(pub(crate))]
129
#[set(pub(crate))]
1310
list: Vec<String>,
1411
#[get(pub(crate))]
15-
opt_str_lifetime_a: Option<&'a T>,
16-
#[set(private)]
12+
opt_value: Option<&'a T>,
1713
#[get_mut(pub(crate))]
18-
opt_str_lifetime_b: Option<&'b str>,
19-
r#type: &'a str,
14+
#[set(private)]
15+
name: String,
2016
}
2117

22-
#[derive(Data, Debug, Clone, DisplayDebugFormat)]
23-
struct r#type<'a, 'b, T: Clone>
24-
where
25-
T: Debug,
26-
{
27-
#[get(pub(crate))]
28-
#[set(pub(crate))]
29-
list: Vec<String>,
30-
#[get(pub(crate))]
31-
opt_str_lifetime_a: Option<&'a T>,
32-
#[set(private)]
33-
#[get_mut(pub(crate))]
34-
opt_str_lifetime_b: Option<&'b str>,
35-
r#type: &'a str,
18+
#[derive(CustomDebug)]
19+
struct User {
20+
name: String,
21+
#[debug(skip)]
22+
password: String,
23+
email: String,
3624
}
3725

38-
impl<'a, 'b, T: Clone + Debug> LombokTest<'a, 'b, T> {
39-
pub fn test_type(&self) {
40-
self.r#type;
41-
}
26+
#[derive(Data, Debug, Clone)]
27+
struct TupleStruct(
28+
#[get(pub)] String,
29+
#[set(pub)] i32,
30+
#[get(pub)]
31+
#[set(pub)]
32+
bool,
33+
);
34+
35+
#[derive(CustomDebug)]
36+
enum Response {
37+
Success {
38+
data: String,
39+
},
40+
Error {
41+
message: String,
42+
#[debug(skip)]
43+
internal_code: u32,
44+
},
4245
}
4346

4447
fn main() {
4548
let mut data: LombokTest<usize> = LombokTest {
4649
list: Vec::new(),
47-
opt_str_lifetime_a: None,
48-
opt_str_lifetime_b: None,
49-
r#type: "type",
50+
opt_value: None,
51+
name: "test".to_string(),
5052
};
5153
let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
5254
data.set_list(list.clone());
53-
match data.get_list() {
54-
left_val => {
55-
assert_eq!(*left_val, list);
56-
}
57-
}
58-
let get_opt_str_lifetime_a: Option<usize> = data.get_opt_str_lifetime_a().cloned();
59-
assert_eq!(get_opt_str_lifetime_a, None);
60-
let get_mut_opt_str_lifetime_b: &mut Option<&str> = data.get_mut_opt_str_lifetime_b();
61-
*get_mut_opt_str_lifetime_b = Some("opt_str_lifetime_b");
62-
assert_eq!(
63-
data.get_mut_opt_str_lifetime_b().clone(),
64-
Some("opt_str_lifetime_b")
65-
);
66-
println!("{}", data.to_string());
55+
assert_eq!(*data.get_list(), list);
56+
let opt_value: &Option<&usize> = data.get_opt_value();
57+
assert_eq!(*opt_value, None);
58+
let name_mut: &mut String = data.get_mut_name();
59+
*name_mut = "updated".to_string();
60+
assert!(!data.to_string().is_empty());
61+
let mut tuple_data: TupleStruct = TupleStruct("hello".to_string(), 42, true);
62+
let field0: &String = tuple_data.get_0();
63+
assert_eq!(field0, "hello");
64+
tuple_data.set_1(100);
65+
let field2: &bool = tuple_data.get_2();
66+
assert_eq!(*field2, true);
67+
tuple_data.set_2(false);
68+
let user: User = User {
69+
name: "Alice".to_string(),
70+
password: "secret123".to_string(),
71+
email: "alice@example.com".to_string(),
72+
};
73+
let user_debug: String = format!("{:?}", user);
74+
assert!(user_debug.contains("Alice"));
75+
assert!(user_debug.contains("alice@example.com"));
76+
assert!(!user_debug.contains("secret123"));
77+
let success: Response = Response::Success {
78+
data: "Operation completed".to_string(),
79+
};
80+
let success_debug: String = format!("{:?}", success);
81+
assert!(success_debug.contains("Operation completed"));
82+
let error: Response = Response::Error {
83+
message: "Something went wrong".to_string(),
84+
internal_code: 500,
85+
};
86+
let error_debug: String = format!("{:?}", error);
87+
assert!(error_debug.contains("Something went wrong"));
88+
assert!(!error_debug.contains("500"));
6789
}

0 commit comments

Comments
 (0)