Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is defining structure inside a function a good way to conceal the structure from other functions?

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?

like image 339
vaartis Avatar asked Nov 12 '16 14:11

vaartis


1 Answers

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.

like image 78
Chris Emerson Avatar answered Oct 06 '22 18:10

Chris Emerson