5 releases
0.5.4 | Mar 24, 2024 |
---|---|
0.5.3 | Mar 24, 2024 |
0.5.2 | Mar 20, 2024 |
0.5.1 | Mar 18, 2024 |
0.5.0 | Mar 18, 2024 |
#348 in Procedural macros
8KB
94 lines
to_query
Structure to HTTP_GET/SQL Query Parameters.
Multiple identical structs may result in duplicated output, but they can be freely combined by accessing arrays
get_strings()
to obtain the desired output.
use to_query::STQuery;
#[derive(STQuery)]
struct HelloStruct {
name: String,
age: Option<u32>,
money: u32,
bank: Option<Bank>,
}
#[derive(STQuery)]
struct Bank {
bank_name: String,
number: Option<u32>,
}
fn fill_struct_test() {
let object = HelloStruct {
name: "hello".to_owned(),
age: Some(123),
money: 0,
bank: Some(Bank {
bank_name: "CoolBank".to_owned(),
number: Some(101),
}),
bank2: Bank{
bank_name: "abc".to_string(),
number: None,
},
};
assert_eq!(
object.get_http_query(),
"name=hello&age=123&money=0&bank_name=CoolBank&number=101&bank_name=abc"
);
assert_eq!(
object.get_sql_query(),
"name=hello,age=123,money=0,bank_name=CoolBank,number=101,bank_name=abc"
);
assert_eq!(
object.get_strings().get(2),
Some("money=0".to_string()).as_ref()
);
assert_eq!(
object.get_strings().last(),
Some("bank_name=abc".to_string()).as_ref()
);
}
Dependencies
~295–750KB
~18K SLoC