Is it recommended to cast an unaliased array to `immutable` after it has been initialized?

The reason for asking is that I would like the following function

void[] rawReadNullTerminated(string path)
    @safe
{
    import std.stdio : File;
    auto file = File(path, `rb`);

    import std.array : uninitializedArray;
    ubyte[] data = uninitializedArray!(ubyte[])(file.size + 1);
    file.rawRead(data);
    data[file.size] = 0;     // null terminator for sentinel

return data; // TODO can we cast this to `immutable(void)[]`?
}

to have an immutable return type.

I'm aware of that I need to verify the contexts as UTF-8 if I want to treat it as text.

Reply via email to