vibe.d beta banner
get vibe.d
0.10.0

Asynchronous I/O that doesn’t get in your way, written in D

Enum member isPolicySerializable

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

enum isPolicySerializable(alias Policy, T) = is(typeof(Policy!T.toRepresentation(T.init))) && is(typeof(Policy!T.fromRepresentation(Policy!T.toRepresentation(T.init))) : T);

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.

See Also

serializeWithPolicy

Example

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));
Authors

Sönke Ludwig

Copyright

© 2013-2016 rejectedsoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.