ExitCode
is a struct, therefore it behaves like a type with many fields which define the types contained in the struct.
That's a bit too off. struct
s in rust are product types. A struct may define zero or more fields. And fields can be named or not. if not, such structs are called tuple structs.
In the doc page, if you clicked on source, it would have taken you to the definition.
pub struct ExitCode(imp::ExitCode);
That's a public struct with one unnamed private field. The type of the private field also happens to be private/internal.
As for why, usually the purpose is providing type safety, a unified interface,... etc. Notice how for example a windows-only extension trait is implemented that allows converting raw u32 exit codes into ExitCode
.
So now you have exit codes possibly sourced from u8 or u32 values depending on the platform. And you need a safe unified interface to represent them.
I hope that's an enough starting point.