nogc 0.0.3

Utilities to write @nogc code


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:

nogc

Build Status Coverage

Utilities to write @nogc code, including converting values to strings (text) and a variant of std.exception.enforce that is @nogc but limits the type of the exception thrown to be NoGcException. Examples:

// text is @system because it returns a slice to a static array
// if you need to store the string you'll need to make a copy
// since consecutive calls will return the same slice and it will
// be mutated
@nogc @system unittest {
    import nogc.conv: text;
    // works with basic types and user defined structs/classes
    assert(text(1, " ", "foo", " ", 2.0) == "1 foo 2.000000");
}


// enforce is @safe, since it internally makes a call to `text` but
// immediately throws an exception, and casting it to `string` makes
// it immutable. Ugly but it works.
@nogc @safe unittest {
    import nogc.exception: enforce;
    import nogc.conv: text;
    const expected = 1;
    const actual = 1;
    enforce(actual == expected, "Expected: ", expected, " but got: ", actual);
}
Authors:
  • Atila Neves
Dependencies:
automem
Versions:
0.5.1 2021-Jul-16
0.5.0 2019-May-24
0.4.0 2019-Apr-01
0.3.1 2019-Mar-22
0.3.0 2019-Feb-19
Show all 16 versions
Download Stats:
  • 7 downloads today

  • 88 downloads this week

  • 361 downloads this month

  • 133011 downloads total

Score:
3.9
Short URL:
nogc.dub.pm