【发布时间】:2022-11-02 14:23:03
【问题描述】:
我试图弄清楚如何访问结构转换的字段以“实现序列化”?
考虑以下代码:
mod Testing {
#[derive(Serialize, Clone)]
pub struct One {
pub valueOne: String,
}
#[derive(Serialize, Clone)]
pub struct Two {
pub valueOne: String,
pub valueTwo: String,
}
}
fn go() -> Result<()> {
let s = Testing::One {
valueOne: "Please work",
};
self.how(s);
Ok(())
}
fn how(
s: impl Serialize,
) -> Result<()> {
// How to access "valueOne" of "s"?
Ok(())
}
【问题讨论】:
-
你不能。但这看起来像一个 XY 问题。
-
你实际上想要完成什么?