Skip to content

Transparent Fields

Compare
Choose a tag to compare
@zhiayang zhiayang released this 28 Apr 16:15
· 1669 commits to dc31d76ae6ac4b6702c1b0ca0232294a124bc386 since this release

Transparent fields are now possible inside structs and @raw unions, and they function like the anonymous structs and unions in C.

They are declared with _ as their name, and of course there can be more than one per struct/union. For example:

struct point3
{
	_: @raw union {
		_: struct {
			x: f64
			y: f64
			z: f64
		}
		raw: [f64: 3]
	}
}

var pt: point3
(pt.x, pt.y, pt.z) = (3.1, 1.7, 5.8)
assert(pt.raw[0] == 3.1)

They don't play nicely with constructors yet, but that's been added to the list of things to do.

Of course, you may have noticed a slight change: there's no more let or var in front of field declarations in struct bodies, it's just name: type now. Also, we've removed the ability for structs to have nested types and static members to simplify stuff a bit.