deserter

Crates.iodeserter
lib.rsdeserter
version0.1.4
sourcesrc
created_at2024-05-26 02:38:08.868734
updated_at2024-05-26 18:36:32.116523
descriptionProcedural macros to initialize Rust structs from JavaScript-like object syntax.
homepage
repository
max_upload_size
id1252314
size44,500
Violet (vi013t)

documentation

README

Deserter

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.

Usage

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`.
}
Commit count: 0

cargo fmt