Skip to content

hrykr/enum-reflect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enum Reflection Rust

github crates.io crates.io

LIBRARY IS IN BETA! SOME FEATURES CAN WORK WRONG!

If you have any error, write about it here

Rust library for enum reflection. Use it to get all fields in enum.

Installation

cargo add enum_reflect

or

[dependencies]
enum_reflect = "0.2.6"

Example

#[derive(EnumReflect)]
pub enum Example {
    Empty,
    Example1 {
        var1: String,
        var2: i32,
    },
    Example2 {
        var1: String,
        var2: i32,
        var3: bool,
    },
}

fn foo() {
    let exml = Example::Example1 { var1: "Hello, World!".to_string(), var2: 32 };
    
    for (name, value) in exml.get_named_fields() {
        println!("Field {} is {}", name, value.to_string());
    }
}

Output:

Field var1 is Hello, World!
Field var2 is 32

About

Rust enum reflection.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages