可以在函数中定义如下 struct :
fn user_status() -> bool {
struct UserStatus {
logined: bool,
name: Option<String>,
}
// ...
true
}
这是一种对其他函数隐藏 struct 的好方法吗? struct 是在每次调用函数时定义的还是只创建一次?
可以在函数中定义如下 struct :
fn user_status() -> bool {
struct UserStatus {
logined: bool,
name: Option<String>,
}
// ...
true
}
这是一种对其他函数隐藏 struct 的好方法吗? struct 是在每次调用函数时定义的还是只创建一次?
我认为这是定义仅在函数中使用的类型的一种完全合理的方法.
类型在编译时定义;当调用函数时,在运行时不会进行"定义".