xreflect

Crates.ioxreflect
lib.rsxreflect
version0.1.0
sourcesrc
created_at2024-07-31 17:34:00.869432
updated_at2024-07-31 17:34:00.869432
descriptionBasic macros for dynamic reflection of structs/enums
homepage
repositoryhttps://github.com/HydrogenMacro/xreflect
max_upload_size
id1321143
size18,244
(HydrogenMacro)

documentation

README

XReflect

A reflection library

Quickstart

use xreflect::Reflect;
// just derive Reflect
#[derive(Reflect)]
pub struct Enemy {
	pub health: u8,
}
#[derive(Reflect)]
pub enum GameState {
	Playing,
	Won { score: i32, remaining_health: u8 },
	Lost(Enemy),
}

fn main() {
	// You can now access and modify fields dynamically
	let mut enemy = Enemy { health: 2 };

	let enemy_health = enemy.get_field::<u8>("health");
	assert_eq!(enemy_health, &2);
	enemy.set_field::<u8>("health", 7);
	assert_eq!(enemy_health, &7);
}
Commit count: 0

cargo fmt