Skip to main content

model

Macro model 

Source
macro_rules! model {
    ($($declarations:tt)*) => { ... };
}
Expand description

Declare models.

One block per module. Each entry names the Rust type, the path the description reaches it by when that differs from the type’s name, and its fields as rust_name: "jsonName" => Type. The JSON name is written once and becomes both the serde rename and the row in SHAPES, which is what stops the two drifting apart (Q61).

ⓘ
model! {
    /// A machine in the tailnet.
    Device {
        id: "id" => String,
        node_id: "nodeId" => String,
    }

    /// How this device is reaching the network.
    ClientConnectivity as "Device.clientConnectivity" {
        endpoints: "endpoints" => Vec<String>,
    }

    /// The same six fields, so the same struct.
    VipServiceInfoPut as "VIPServiceInfoPut" is VipServiceInfo;
}

Every field is optional and every type is the one inside the Option: the control plane omits what does not apply, and a model that demanded a field would fail to parse a body a caller could have used.

The last form declares a schema that some other model already has the shape of. The description does that where one body is another under a second name, and a second struct there would be six duplicated fields and a conversion between them that says nothing.