Module vocab
Expand description
How a closed vocabulary crosses the boundary as a typed value.
Every convention a caller names — a business-day convention, a frequency, a
day count — is a closed set in the core, parsed by the core’s own FromStr.
The string has always crossed; this module lets the value cross beside it,
so a notebook can complete Frequency.SemiAnnual where it typed
"SemiAnnual", without taking the string away from anyone.
Two pieces, and a rule between them:
Crossingsays which Python class a core vocabulary reaches Python as, and how a value of that class and a spelling each become the core value.Namedis the parameter type an entry point declares. ItsFromPyObjectaccepts the class or the string, and refuses anything else naming both, so the two accepted forms are visible to pyo3, to the stub and to the reader of the signature.
The rule: the class is a spelling of the core value, never a second
vocabulary. A member’s code() is the string the parser would have taken,
and the parser and the class agree because both are generated from the
core’s declaration. Nothing here restates an accepted list.
simple_vocabulary! generates the class for a vocabulary that carries no
payload. A vocabulary that does — a frequency of n days, a roll on the
nth — is a frozen value class written by hand on the same template, in
the module that owns it.
Macros§
- simple_
vocabulary 🔒 - A core vocabulary with no payload, crossing as a pyo3 simple enum.
Structs§
- Named 🔒
- A vocabulary value as a Python caller names it: the class, or its spelling.
Traits§
- Crossing 🔒
- A core vocabulary that reaches Python as a class.