| Crates.io | deserter |
| lib.rs | deserter |
| version | 0.1.4 |
| created_at | 2024-05-26 02:38:08.868734+00 |
| updated_at | 2024-05-26 18:36:32.116523+00 |
| description | Procedural macros to initialize Rust structs from JavaScript-like object syntax. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1252314 |
| size | 44,500 |
A set of two procedural macros for initializing structs with a JavaScript-like syntax. In other words, deserializing data with compile-time checking into struct values.
The #[loadable] attribute can be added on structs which can be loaded, and the load! macro can be used to initialize a loadable struct. All fields which are themselves structs must also be marked #[loadable]:
use deserter::{load, loadable};
#[loadable]
struct ZipCode {
digits: u32,
}
#[loadable]
struct Address {
house: u32,
street: &'static str,
city: &'static str,
zip_code: ZipCode,
}
#[loadable]
struct Person {
name: &'static str,
age: u32,
address: Address,
}
fn example() {
let john = load!(
Person {
name = "john",
age = 30,
address = {
house = 101,
street = "Main Street",
city = "New York",
zip_code = {
digits = 100200
}
}
}
);
// do things with john, it is a `Person`.
}