Nested Functions, Structs, and Classes
Up to this point, we have been defining functions, structs, and classes in the outermost scopes (i.e., the module scope). They can be defined in inner scopes as well. Defining them in inner scopes helps with encapsulation by narrowing the visibility of their symbols, and creating closures, which we covered in the function pointers, delegates, and lambdas chapter.
As an example, the following
outerFunc() function contains definitions of a nested function, a nested struct, and a nested class: