Using reflection to enumerate through the fields of a struct at runtime

后端 未结 2 860
盖世英雄少女心
盖世英雄少女心 2021-01-24 02:06

If I have a data structure like this:

struct Point {
    x: i32,
    y: i32,
}

impl Point {
    fn setX(&mut self, x: i32) -> &mut Point {
        s         


        
2条回答
  •  一个人的身影
    2021-01-24 02:44

    Rust does not really support this kind of reflection at runtime, no.

    In theory, you might be able to write a syntax extension that would let you generate some code that would do something like this, maybe...

提交回复
热议问题