vibe.d beta banner
get vibe.d
0.10.1

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

Function enforceWireVersionConstraints

Unsets nullable fields not matching the server version as defined per UDAs.

void enforceWireVersionConstraints(T) (
  ref T field,
  int serverVersion,
  string file = __FILE__,
  size_t line = __LINE__
) @safe;

Example

struct SomeMongoCommand
{
	@embedNullable @since(WireVersion.v34)
	Nullable!int a;

	@embedNullable @until(WireVersion.v30)
	Nullable!int b;
}

SomeMongoCommand cmd;
cmd.a = 1;
cmd.b = 2;
assert(!cmd.a.isNull);
assert(!cmd.b.isNull);

SomeMongoCommand test = cmd;
enforceWireVersionConstraints(test, WireVersion.v30);
assert(test.a.isNull);
assert(!test.b.isNull);

test = cmd;
enforceWireVersionConstraints(test, WireVersion.v32);
assert(test.a.isNull);
assert(test.b.isNull);

test = cmd;
enforceWireVersionConstraints(test, WireVersion.v34);
assert(!test.a.isNull);
assert(test.b.isNull);
Authors

Sönke Ludwig

Copyright

© 2012-2016 Sönke Ludwig

License

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