signature_of

func signature_of(collection: &DocumentableCollection, entry: &DocumentableEntry) -> String

Produces the display signature used in headings and anchors.

Function, method, and effect headers preserve their source spelling so ownership, labels, effects, and constraints remain part of the public contract. Other modeled declarations are rendered from their structured entries; missing references use ?.

View Source
pub func signature_of(collection: &DocumentableCollection, entry: &DocumentableEntry) -> String {
	match entry.value {
		.builtin(value) -> "builtin " + value.name,
		.function(function) -> function.signature.clone(),
		.global(global) -> {
			let out = "let " + global.name
			if let .some(type_id) = global.type {
				out = out + ": " + type_name(collection: collection, id: type_id)
			}
			out
		},
		.method(method) -> method.function.signature.clone(),
		.nominal(nominal) -> match nominal {
			.#"struct"(name: name, generics: generics, properties: _, methods: _) -> "struct " + name + generics_text(collection: collection, generics: generics),
			.#"enum"(name: name, generics: generics, variants: _, methods: _) -> "enum " + name + generics_text(collection: collection, generics: generics),
			.#"protocol"(name: name, generics: generics, properties: _, methods: _) -> "protocol " + name + generics_text(collection: collection, generics: generics)
		},
		.property(property) -> {
			let prefix = if property.is_static { "static let " } else { "let " }
			let out = prefix + property.name
			if let .some(type_id) = property.type {
				out = out + ": " + type_name(collection: collection, id: type_id)
			}
			out
		},
		.variant(variant) -> {
			let payloads: [String] = []
			for id in variant.payloads {
				payloads.push(type_name(collection: collection, id: id))
			}
			if payloads.is_empty() {
				"case " + variant.name
			} else {
				"case " + variant.name + "(" + join_strings(parts: payloads, separator: ", ") + ")"
			}
		},
		.effect_declaration(declaration) -> declaration.signature.clone(),
		.type(value) -> value.name,
		.#"effect"(value) -> "'" + value.name,
		.parameter(parameter) -> parameter.name
	}
}