| Crates.io | filterstruct |
| lib.rs | filterstruct |
| version | 0.1.0 |
| created_at | 2025-11-04 05:02:08.040917+00 |
| updated_at | 2025-11-04 05:02:08.040917+00 |
| description | A simple macro for creating struct instances with ergonomic syntax, useful for filters. |
| homepage | |
| repository | https://github.com/MrRevillod/filterstruct |
| max_upload_size | |
| id | 1915757 |
| size | 9,860 |
Simple macro for create instances of structs with more ergonomic syntax.
cargo add filterstruct
Define your struct as usual:
#[derive(Default, Clone)]
pub struct UserFilter {
pub id: Option<Uuid>,
pub email: Option<String>,
pub search: Option<String>,
pub page: u64,
}
Then, define your filter using the filter! macro:
macro_rules! user_filter {
($($field:ident $(: $value:expr)?),* $(,)?) => {
::filterstruct::filter!(UserFilter, { $($field $(: $value)?),* })
};
}
Now you can create instances of UserFilter using the user_filter! macro:
let filter = user_filter! {
id: Uuid::new_v4(),
}
This will create a UserFilter instance with the id field set to a new UUID, and all other fields set to their default values.
Also, you can use shorthand for fields that you want to set to Some(value):
let email = String::from("some@domain.com");
let filter = user_filter! {
email,
page: 2,
}