vibe.d beta banner
get vibe.d
0.10.1

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

Alias ChainedPolicy

Chains serialization policy.

alias ChainedPolicy(alias Primary, Fallbacks...) = Primary;

Constructs a serialization policy that given a type T will apply the first compatible policy toRepresentation and fromRepresentation functions. Policies are evaluated left-to-right according to isPolicySerializable.

See Also

serializeWithPolicy

Example

import std.conv;

// To be represented as the boxed value when serialized
static struct Box(T) {
	T value;
}
// Also to berepresented as the boxed value when serialized, but has
// a different way to access the value.
static struct Box2(T) {
	private T v;
	ref T get() {
		return v;
	}
}
template BoxPol(S)
{
	auto toRepresentation(S s) {
		return s.value;
	}

	S fromRepresentation(typeof(toRepresentation(S.init)) v) {
		return S(v);
	}
}
template Box2Pol(S)
{
	auto toRepresentation(S s) {
		return s.get();
	}

	S fromRepresentation(typeof(toRepresentation(S.init)) v) {
		S s;
		s.get() = v;
		return s;
	}
}
alias ChainPol = ChainedPolicy!(BoxPol, Box2Pol);
static assert(!isPolicySerializable!(BoxPol, Box2!int));
static assert(!isPolicySerializable!(Box2Pol, Box!int));
static assert(isPolicySerializable!(ChainPol, Box!int));
static assert(isPolicySerializable!(ChainPol, Box2!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.