isPolicySerializable

Checks if a given policy supports custom serialization for a given type.

A class or struct type is custom serializable according to a policy if the policy defines a pair of toRepresentation/fromRepresentation functions. Any class or struct type that has this trait for the policy supplied to serializeWithPolicy will be serialized by using the return value of the policy toRepresentation function instead of the original value.

This trait has precedence over isCustomSerializable, isISOExtStringSerializable and isStringSerializable.

template isPolicySerializable (
alias Policy
T
) {}

Members

Variables

isPolicySerializable
enum bool isPolicySerializable;
Undocumented in source.

Examples

import std.conv;

// represented as the boxed value when serialized
static struct Box(T) {
	T value;
}

template BoxPol(S)
{
	auto toRepresentation(S s) {
		return s.value;
	}

	S fromRepresentation(typeof(S.init.value) v) {
		return S(v);
	}
}
static assert(isPolicySerializable!(BoxPol, Box!int));

See Also

vibe.data.serialization.serializeWithPolicy

Meta