dullsafety 0.0.2
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 .asNonNull()
, eg:
void exampleFunction(NonNull!string message);
exampleFunction("Hello, World!".asNonNull());
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();
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 .asNonNull()
, 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 exasperate the Dlang team into adding native support for null-restricted types.
- 0.0.2 released 4 days ago
- Protonull/DullSafety
- Apache-2.0
- Copyright © 2025, Protonull
- Authors:
- Dependencies:
- none
- Versions:
-
0.0.2 2025-Aug-25 0.0.1 2025-Aug-23 ~master 2025-Aug-25 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
0 downloads total
-
- Score:
- 0.0
- Short URL:
- dullsafety.dub.pm