Cool pattern or tragic?
Guillaume Piolat
first.name at gmail.com
Fri Aug 25 21:00:08 UTC 2023
The idea is to deliberately mark @system functions that need
special scrutiny to use, regardless of their memory-safety.
Function that would typically be named `assumeXXX`.
```d
class MyEncodedThing
{
Encoding encoding;
/// Unsafe cast of encoding.
void assumeEncoding (Encoding encoding) /* here */ @system /*
here */
{
this.encoding = encoding;
}
}
char* assumeZeroTerminated(char[] str) @system
{
return str.ptr;
}
```
That way, @safe code will still need to manually @trust them.
More information about the Digitalmars-d-learn
mailing list