serializerInvalidReason

Utility function to check if a serializer conforms to the requirements

string
serializerInvalidReason
()
()

Return Value

Type: string

An error message, or null if the serializer is conformant

Examples

template Nothing () {}
static assert(serializerInvalidReason!(Nothing!()).length);
static assert(serializerInvalidReason!(Object).length);
// Older frontend do not support passing basic type as template alias parameters
//static assert(serializerInvalidReason!(int).length);

// Note: We don't test the error message. Invert the condition to see them.

// Valid
static struct S1
{
    static immutable(void)[] serialize (T) (T v) { return null; }
    static QT deserialize (QT) (immutable(void)[] v) { return QT.init; }
}
static assert(!serializerInvalidReason!(S1).length, serializerInvalidReason!(S1));

// Valid: Type conversions are performed (ubyte[] => void[])
static struct S2
{
    static immutable(ubyte)[] serialize (T) (T v) { return null; }
    static QT deserialize (QT) (immutable(void)[] v) { return QT.init; }
}
static assert(!serializerInvalidReason!(S2).length, serializerInvalidReason!(S2));

// Invalid: `void[]` =/> `ubyte[]`
static struct S3
{
    static immutable(void)[] serialize (T) (T v) { return null; }
    static QT deserialize (QT) (immutable(ubyte)[] v) { return QT.init; }
}
static assert(serializerInvalidReason!(S3).length, serializerInvalidReason!(S3));

Meta