Macro keypath_proc_macros::keypath[][src]

keypath!() { /* proc-macro */ }
Expand description

Create a strongly-typed KeyPath.

This verifies at compile-time that the path is valid.

This macro expects a type name, followed by one or more path components. Path components may be either fields or indices.

  • field: a single ‘.’ character, followed by either a valid identifier or a single unsized integer.
  • indicies: a pair of brackets ([]) containing either a string literal or an unsized integer.

Fields should correspond to named or unnamed fields on the base type. Indicies refer to members of collections.

Examples

The following are semantically valid keypaths. (Their actual validity would depend on these fields existing in the underlying types.)

keypath!(Person.profile.name);
keypath!(Element.size.0);
keypath!(Person.friends[10].name);
keypath!(Person.friends["常羽辰"].address);
keypath!(Thing.field.0["friends"].count);
keypath!(Thing.1[2][3].size.width);