Skip to main content

Module rust

Module rust 

Source
Expand description

Writing a universe out as Rust.

Rust has no inheritance, so there is a choice to make and it is worth being explicit about. A child could hold its parent in a flattened field, keeping the shape of the declaration; or it could carry every field it has, inherited or not. This does the second.

Flattening wins because the wire is what matters. Circle serializes to the same object either way, but flattened it also reads like the object — circle.id rather than circle.base.id, one level however deep the hierarchy went. Rust was never going to give subtype polymorphism anyway; what it gives is traits, and an interface becomes one, so the polymorphism that does exist lands where Rust can actually use it.

§Generics

Generic declarations and signatures keep their parameters, and a bound, being an interface, is a trait bound. Two things differ from the universe:

  • Rust refuses a struct, an enum or an alias with a parameter it never uses, and the checker already knows which those are, so they are left out — of the declaration, and of every argument list that names it. A parameter that is not used cannot change what a value holds, so nothing on the wire moves.
  • A body clones what it reads and may compare what it is given, so a signature with a body asks Clone + PartialEq of each of its parameters. One without a body asks only what the universe asks.

A type alias’s bounds are left out too: Rust does not enforce them there and says so.

§Bytes

Bytes travel as base64 text, which is how every language’s JSON can hold them. serde writes a Vec<u8> as an array of numbers instead, and cannot be told otherwise for a Vec<Vec<u8>> or an Option<Vec<u8>> without a wrapper, so bytes are a type of their own, Bytes. There is one, shared by every universe, in a module beside them named unitype_support, which is written only when something uses it.

Structs§

Rust
The Rust backend.

Functions§

literal
Writes a value as a Rust literal.