Crates.io | to_query |
lib.rs | to_query |
version | 0.5.4 |
source | src |
created_at | 2024-03-18 09:06:10.296188 |
updated_at | 2024-03-24 10:12:14.658687 |
description | Structure to HTTP_GET/SQL Query Parameters |
homepage | |
repository | https://github.com/Futsukai/struct_to_query.git |
max_upload_size | |
id | 1177460 |
size | 8,833 |
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()
);
}