You can define a structure inside a function like this:
fn user_status() -> bool {
struct UserStatus {
logined: bool,
name: Option<String>,
}
// ...
true
}
Is this a good way to conceal structure from other functions and is structure defined every time something calls the function or it is created just once?
I think this is a perfectly reasonable way to define a type only used within a function.
Types are defined at compile time; there's no "defining" going on at runtime when functions are called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With