vibe.d beta banner
get vibe.d

Enum member isStringSerializable

Checks if a given type has a string serialization representation.

A class or struct type is string serializable if it defines a pair of toString/fromString methods. Any class or struct type that has this trait will be serialized by using the return value of it's toString method instead of the original value.


enum isStringSerializable(T) = is(typeof(T.init.toString()) == string) && is(typeof(T.fromString("")) == T);


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

Sönke Ludwig


© 2013-2014 rejectedsoftware e.K.


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