Module is unique compilation unit to organize code members in project.
module First;
struct Vector
{
int X;
int Y;
}Module name can be dotted:
module First.Second.Third.Fourth;
struct Vector
{
int X;
int Y;
}Any module can be imported to another by use keyword
// First.cstar
module First;
// Second.cstar
module Second;
use First;Members access modifiers can be applied to:
- top-level and nested
structs - fields
- functions
Access to members without public/internal modifiers is limited to the containing scope.
// First.cstar
module First;
struct Vector
{
int X;
int Y;
}
struct Some
{
Vector Vector;
// ^^^^^^ ERROR: 'Vector' is not accessible
}
// Second.cstar
module Second;
use First;
struct AnotherSome
{
Vector Vector;
// ^^^^^^ ERROR: 'Vector' is not accessible
}Access to members with public modifier isn't restricted.
// First.cstar
module First;
public struct Vector
{
int X;
int Y;
}
struct Some
{
Vector Vector; // ok
}
// Second.cstar
module Second;
use First;
struct AnotherSome
{
Vector Vector; // ok
}Access to members with internal modifier is limited to the current assembly.
// MyProject - First.cstar
module First;
internal struct Vector
{
int X;
int Y;
}
struct Some
{
Vector Vector; // ok
}
// MyProject - Second.cstar
module Second;
use First;
struct AnotherSome
{
Vector Vector; // ok
}
// MyAnotherProject - Third.cstar
module Third;
use First;
struct AnotherSome
{
Vector Vector;
// ^^^^^^ ERROR: 'Vector' is not accessible
}