dullsafety 0.0.1

Approximate null-safety for Dlang


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:

DullSafety

This is a source-library package that attempts to approximate null-restricted types in D. It's somewhat hilarious to me that D's expansive feature set allows such approximations, but still hasn't managed to natively support null-restricted types. It's honestly kind of impressive.

How to use

You use this by prefixing a null-assignable type with NonNull! (eg: NonNull!string/NonNull!(int*)). You should limit your usage of this to the "fringes" of your APIs, ie, function parameters and return types.

Converting from a type into its NonNull! equivalent is as easy as using .into(), eg:

void exampleFunction(NonNull!string message);
exampleFunction("Hello, World!".into());

Unwrapping happens automatically, eg:

NonNull!string exampleFunction();
string result = exampleFunction(); // string has been automatically unwrapped from `NonNull!string`

For APIs that do not [wish to] use NonNull!, this package comes with a convenience assertion method:

string exampleThirdPartyFunction();
// Keep in mind that this IS an assertion, so a failure will crash your program.
// Only use this when a null value is invalid state.
string result = exampleThirdPartyFunction().assertNonNull();

Warnings and advisories

You should avoid using NonNull! for variable types unless they are const or immutable.

You should also NEVER create a default-initialised or void-initialised NonNull!, as while this is valid D code, it violates the contract of NonNull!. You should ALWAYS use .into(), no exceptions.

You may run into issues with the automatic unboxing, in which case you should use the .unwrap() method.

Licence

This project is licensed under Apache 2.0.

Purpose

The ultimate purpose of this package is to be obviated by native null-restricted types.

Authors:
  • Protonull
Dependencies:
none
Versions:
0.0.2 2025-Aug-25
0.0.1 2025-Aug-23
~master 2025-Aug-25
Show all 3 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 0 downloads total

Score:
0.0
Short URL:
dullsafety.dub.pm