Can be @trusted as long as this type is used correctly.
A postblit is present on this object, but not explicitly documented in the source.
These are the only ways to access the refcounted payload (but the store MUST be initialized)
Accesses the refcounted store, usually to check if (or ensure that) it is initialized.
Protects a pointer to some reference counted payload.
static uint nDestroyed = 0; struct Resource { string name; this(string name) { this.name = name; } @disable this(this); ~this() { debug ++nDestroyed; } } { auto rc1 = RefCountedTrusted!Resource("thing"); assert(rc1.refCountedStore.isInitialized); rc1.refCountedStore.ensureInitialized(); { auto rc2 = rc1; RefCountedTrusted!Resource rc3; rc3 = rc2; () @trusted { assert(rc3.refCountedPayload.name == "thing"); }(); } // ~rc2 and ~rc3 didn't destroy the resource: there's still one ref debug assert(nDestroyed == 0); } // now the last reference is removed and the resource is destroyed debug assert(nDestroyed == 1);
XXX: See related bug reports and pull requests.
Adapted RefCounted with a @trusted destructor.