boxed

Constructor function to create a shared Boxed with an unqualified template type.

shared(Sendable)
boxed
(
T
)

Parameters

payload T

Payload whose type to instantiate the Boxed with, and then assign to its internal payload.

Return Value

Type: shared(Sendable)

A shared Boxed!T where T` is the unqualified type of the payload.

Examples

IRCEvent event;  // ...
mainThread.send(ThreadMessage.busMessage("header", boxed(event)));
mainThread.send(ThreadMessage.busMessage("other header", boxed("text payload")));
mainThread.send(ThreadMessage.busMessage("ladida", boxed(42)));
{
    auto msg = boxed("asdf");
    auto asCast = cast(Boxed!string)msg;
    assert((msg !is null), "Incorrectly cast message: " ~ typeof(asCast).stringof);
    asCast = null;  // silence dscanner
}
{
    auto msg = boxed(123_456);
    auto asCast = cast(Boxed!int)msg;
    assert((msg !is null), "Incorrectly cast message: " ~ typeof(asCast).stringof);
    asCast = null;  // silence dscanner
}
{
    struct Foo {}
    auto msg = boxed(Foo());
    auto asCast = cast(Boxed!Foo)msg;
    assert((msg !is null), "Incorrectly cast message: " ~ typeof(asCast).stringof);
    asCast = null;  // silence dscanner
}