inline @trusted code

ikod geller.garry at gmail.com
Tue Jan 30 15:05:38 UTC 2018


Hello,

Several times I faced with next problem: I have "@safe" routine 
with few calls to @system functions inside: OS calls (recv, send, 
kqueue) os some phobos unsafe functions like assumeUnique. I'd 
like not to wrap these @system functions in @trusted wrappers, 
but somehow mark these calls @trusted inline.

In ideal case this should look like

import std.exception;

void main() @safe
{
     ubyte[] a;
     @trusted {
     	auto b = assumeUnique(a);
     };
}

But the closest variant is

import std.exception;

void main() @safe
{
     ubyte[] a;
     delegate void() @trusted {
     	auto b = assumeUnique(a);
     }();
}

Which looks a bit verbose.

How do you solve this problem?

Thanks!


More information about the Digitalmars-d-learn mailing list