something I may have actually used in real code writing a
low-level networking library:
struct Packet
{
immutable etherType = 0x0800; // IPv4 by default;
// ...
this(bool IPv6)
{
if (!IPv6)
return; // fine with default, same as Packet.init
else
{
etherType = 0x86DD;
// ...
}
}
}
void main()
{
auto buffer = cast(ubyte[])(Packet(true));
}