notnull 0.1.0

A small library to make null checks fun.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

NotNull

alt text

A super simple function to make null checks of pointers a breeze for the D Programming Language

$(D nnL) function:

unittest {
	import std.exception : assertThrown, assertNotThrown;
	struct A {
	}

	struct B {
		A* a;
	}

	B* b;
	assertThrown!NullPointerException(nnL(b));
	
	b = new B;
	assertNotThrown(nnL(b));

	assertThrown!NullPointerException(nnL(b).a.nnL());
	assertThrown!NullPointerException(b.nnL().a.nnL());

	b.a = new A;
	assertNotThrown(nnL(b).a.nnL());
}

$(D Null) type:

$(D Null) could be considered to be the successor to $(D Nullable). It allows to create a type how is not only nullable but also can carry $(D Exception)s.


pure unittest {
	alias NullInt = Null!(int, NullPointerException, Exception);
	NullInt ni;
	assert(ni.isNull);
	assert(!ni.isNotNull);

	ni = 10;
	assert(!ni.isNull);
	assert(ni.isNotNull);
	assert(ni.get() == 10);

	ni.set!NullPointerException();
	assert(ni.isNull);
}
Authors:
  • burner
Dependencies:
none
Versions:
0.1.0 2017-Aug-08
0.0.1 2017-Jul-29
~master 2017-Aug-08
Show all 3 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 16 downloads total

Score:
0.5
Short URL:
notnull.dub.pm