vibe.d beta banner
get vibe.d

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

Enum member isStringSerializable

Checks if a given type has a string serialization representation.

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

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.


import std.conv;

// represented as a string when serialized
static struct S {
	int value;

	// dummy example implementations
	string toString() const { return!string(); }
	static S fromString(string s) { return S(!int()); }

static assert(isStringSerializable!S);

Sönke Ludwig


© 2013-2016 rejectedsoftware e.K.


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