You frequently can, but remember that when you mark something
as @trusted, you're telling the compiler that you've verified
that the code is memory-safe (whereas with @safe, the compiler
has verified that). So, if you mark code with @trusted when
it's not actually memory-safe, you make it so that @safe code
can call code which isn't memory-safe, and the @safe code then
isn't actually memory-safe.
So, ideally, you'd do whatever @system stuff you need to do
within a function and encapsulate the @system stuff in a way
that you can mark the function as @trusted and have an API
which is memory-safe, but whether you can do that or not
depends on what your code is doing.
- Jonathan M Davis
This is a really good explanation, thank you.