Expand description
Source: Analysis/include/Luau/JsonEmitter.h (lines 155-167, hand-ported)
C++ template:
template<typename T>
void writePair(std::string_view name, T value)
{
if (finished) return;
emitter->writeComma();
write(*emitter, name);
emitter->writeRaw(':');
write(*emitter, value);
}C++ resolves the two write(*emitter, ...) calls by overload resolution over
the write(JsonEmitter&, T) family. Rust expresses that overload set as the
WriteJson trait defined here: every value that can be a JSON value impls it
by delegating to the corresponding write_json_emitter_* free function (the
ported C++ write overloads). The concrete impl WriteJson for <T> blocks
are colocated with the function that ports the matching overload:
- scalars / strings / pointers -> this file
Vec<T>-> functions/write_json_emitter.rsOption<T>-> functions/write_json_emitter_alt_b.rsunordered_map<String, T>/ hash maps -> functions/write_json_emitter_alt_c.rs
Traitsยง
- Write
Json - Rust shape of the overloaded
void write(JsonEmitter&, T)family. A type implements this iff there is awrite(JsonEmitter&, T)overload for it in C++. The single method writes the JSON encoding ofselfintoemitter.